Simple python solution


  • 0
    B
    def subsetsWithDup(self, s):
            def dfs(cur, s, path):
                ret.append(path)
                for i in range(cur, len(s)):
                    if i > cur and s[i] == s[i-1]: continue
                    dfs(i+1, s, path + [s[i]])
            
            s.sort()
            ret = []
            dfs(0, s, [])
            return ret

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.