We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fa25fab commit ce1a80bCopy full SHA for ce1a80b
problems/0078.子集.md
@@ -205,7 +205,20 @@ class Solution {
205
```
206
207
Python:
208
-
+```python3
209
+class Solution:
210
+ def subsets(self, nums: List[int]) -> List[List[int]]:
211
+ res = []
212
+ path = []
213
+ def backtrack(nums,startIndex):
214
+ res.append(path[:]) #收集子集,要放在终止添加的上面,否则会漏掉自己
215
+ for i in range(startIndex,len(nums)): #当startIndex已经大于数组的长度了,就终止了,for循环本来也结束了,所以不需要终止条件
216
+ path.append(nums[i])
217
+ backtrack(nums,i+1) #递归
218
+ path.pop() #回溯
219
+ backtrack(nums,0)
220
+ return res
221
+```
222
223
Go:
224
```Go
0 commit comments