- Notifications
You must be signed in to change notification settings - Fork 306
/
Copy path78.py
33 lines (30 loc) · 708 Bytes
/
78.py
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
26
27
28
29
30
31
32
33
# Yu Zhou
# 78. Subsets
# Given a set of distinct integers, nums, return all possible subsets.
# Note: The solution set must not contain duplicate subsets.
# If nums = [1,2,3], a solution is:
# [
# [3],
# [1],
# [2],
# [1,2,3],
# [1,3],
# [2,3],
# [1,2],
# []
# ]
classSolution(object):
defsubsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
self.res= []
defdfs(nums, temp, i):
self.res.append(temp[:])
foriinxrange(i, len(nums)):
temp.append(nums[i])
dfs(nums, temp, i+1)
temp.pop()
dfs(nums, [], 0)
returnself.res