File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -278,6 +278,28 @@ def backtrack(...):
278278
279279![ labuladong] ( ../pictures/labuladong.png )
280280
281+ [ Zongshuai] ( https://github.com/zongshuai818 ) 提供全排列 Python3解法代码:
282+
283+ ``` python
284+ class Solution :
285+ def permute (self , nums : List[int ]) -> List[List[int ]]:
286+ # 回溯算法
287+ result = []
288+ track = [] # 可行路径
289+ def trackBack (nums_ , track_ ):
290+ if len (track_) == len (nums_): # 满足终止条件
291+ result.append(track_[:])
292+ return
293+ for i in nums_: # 所有可选项
294+ if i in track_: # 判断是否可选
295+ continue
296+ track.append(i) # 选择
297+ trackBack(nums_, track_) # 递归
298+ track.pop() # 回溯
299+ trackBack(nums, track)
300+ return result
301+ ```
302+
281303[ 上一篇:动态规划答疑篇] ( ../动态规划系列/最优子结构.md )
282304
283305[ 下一篇:二分查找解题框架] ( ../算法思维系列/二分查找详解.md )
You can’t perform that action at this time.
0 commit comments