Advertisement
jinhuang1102

90. SubsetII

Nov 11th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. # 90. SubsetII
  2. # 这道题的思路 is similar with the subsetI, the only difference is in this question the duplicate number
  3. #             is in the original array.
  4. def backtrackSubsetDup(nums, idx, temp, res):
  5.     res.append(temp)
  6.     for i in range(idx, len(nums)):
  7.         if i > idx and nums[i] == nums[i-1]: # to skip the duplicate number “i > idx" is garente the i-1 will
  8.                                              # will not out the index limitation.
  9.             continue
  10.         backtrackSubsetDup(nums, i+1, temp+[nums[i]], res)
  11.  
  12.     return
  13.  
  14.  
  15. def subsetWithDup(nums):
  16.     res = []
  17.     nums.sort()
  18.     backtrack(nums, 0, [], res)
  19.     return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement