Skip to content

Instantly share code, notes, and snippets.

@ChongyeWang
Created March 16, 2019 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChongyeWang/f53812c862e800d464f7e97801e83bf0 to your computer and use it in GitHub Desktop.
Save ChongyeWang/f53812c862e800d464f7e97801e83bf0 to your computer and use it in GitHub Desktop.
class Solution(object):
def subsetsWithDup(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
nums = sorted(nums)
result = []
temp = []
self.backtrack(nums, result, temp, 0)
return result
def backtrack(self, nums, result, temp, start):
result.append(temp[:])
for i in range(start, len(nums)):
if i > start and nums[i] == nums[i - 1]: continue
temp.append(nums[i])
self.backtrack(nums, result, temp, i + 1)
temp.pop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment