#78
Subsets
medium· Backtrackingruns: 0Given an integer array nums of unique elements, 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 / 404
class Solution:
def subsets(self, nums: list[int]) -> list[list[int]]:
result = []
path = []
def backtrack(i: int) -> None:
if i == len(nums):
result.append(path[:])
return
path.append(nums[i])
backtrack(i + 1)
path.pop()
backtrack(i + 1)
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.