#90
Subsets II
medium· Backtrackingruns: 0Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution must not contain duplicate subsets and may be returned in any order.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 492
class Solution:
def subsetsWithDup(self, nums: list[int]) -> list[list[int]]:
nums.sort()
result = []
path = []
def backtrack(start: int) -> None:
result.append(path[:])
for i in range(start, len(nums)):
if i > start and nums[i] == nums[i - 1]:
continue
path.append(nums[i])
backtrack(i + 1)
path.pop()
backtrack(0)
return result
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.