leetcode 中等难度题,考察的递归!!!
思路:nums的第一个元素,加上除该元素的所有元素递归!!!
标准写法(需要学习总结!!!):
class Solution(object):
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
if len(nums) <= 1:
return [nums]
answer = []
for i, num in enumerate(nums):
n = nums[:i] + nums[i+1:]
for y in self.permute(n):
answer.append([num] + y)
return answer
网友评论