Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
420 B
2
Indexable
Never
class Solution:
    def subsets(self, nums: List[int]) -> List[List[int]]:
        def backtrack(currIdx):
            if currIdx == len(nums):
                subsets.append(currSubset[:]) #O(n)
                return
            
            currSubset.append(nums[currIdx])
            backtrack(currIdx + 1) # O(1)
            
        subsets = []
        currSubset = []
        backtrack(0)
        return subsets