Skip to content

Commit

Permalink
Time: 0 ms (100%), Space: 16.8 MB (72.87%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
ykdy3951 committed Nov 21, 2024
1 parent 376ff08 commit 4c4a3b3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 0090-subsets-ii/0090-subsets-ii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution:
def backtracking(self, res = [], start_idx = 0):
self.ans.append(res)

for i in range(start_idx, self.n):
if self.vst[i]:
continue

if i > 0 and self.nums[i] == self.nums[i-1] and not self.vst[i - 1]:
continue

self.vst[i] = True
self.backtracking(res + [self.nums[i]], i + 1)
self.vst[i] = False


def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
nums.sort()
self.nums = nums
self.n = len(nums)
self.vst = [False] * self.n
self.ans = []
self.backtracking()
return self.ans

0 comments on commit 4c4a3b3

Please sign in to comment.