力扣 78. 子集

回溯思想 + dfs实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def subsets(nums):
def dfs(i, tmp):
if i >= n_len:
return

tmp.append(nums[i])
res.append(tmp)

for j in range(i + 1, n_len):
dfs(j, tmp.copy())


n_len = len(nums)
res = [[]]
for i in range(n_len):
dfs(i, [])

return res
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信