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 14221a5Copy full SHA for 14221a5
problems/0046.全排列.md
@@ -182,7 +182,23 @@ class Solution {
182
```
183
184
Python:
185
-
+```python3
186
+class Solution:
187
+ def permute(self, nums: List[int]) -> List[List[int]]:
188
+ res = [] #存放符合条件结果的集合
189
+ path = [] #用来存放符合条件的结果
190
+ def backtrack(nums):
191
+ if len(path) == len(nums):
192
+ return res.append(path[:]) #此时说明找到了一组
193
+ for i in range(0,len(nums)):
194
+ if nums[i] in path: #path里已经收录的元素,直接跳过
195
+ continue
196
+ path.append(nums[i])
197
+ backtrack(nums) #递归
198
+ path.pop() #回溯
199
+ backtrack(nums)
200
+ return res
201
+```
202
203
Go:
204
```Go
0 commit comments