-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathanswer.py
More file actions
25 lines (21 loc) · 715 Bytes
/
answer.py
File metadata and controls
25 lines (21 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/python3
#------------------------------------------------------------------------------
# Backtracking Solution
#------------------------------------------------------------------------------
import copy
class Solution:
def subsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
def helper(curr, idx):
for j in range(idx, len(nums)):
curr.append(nums[j])
if curr not in power_set:
power_set.append(copy.deepcopy(curr))
helper(curr, j+1)
curr.pop()
power_set = [[]]
helper([], 0)
return power_set