狀態(tài)很不好
https://leetcode-cn.com/problems/permutations/
一道很有意思的題目
全排列 深度優(yōu)先斩箫,說了很久,其實理解的不太好,遞歸也是
先寫了代碼
刷下題
class Solution:
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
self.ans = []
sub = []
self.dfs(nums,sub)
return self.ans
def dfs(self,nums,sub):
if len(nums) == len(sub):
self.ans.append(sub[:])
for m in nums:
if m in sub:
continue
sub.append(m)
self.dfs(nums,sub)
sub.remove(m)