class Solution: def permute(self, nums: List[int]) -> 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
本文共 392 字,大约阅读时间需要 1 分钟。
class Solution: def permute(self, nums: List[int]) -> 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
转载于:https://www.cnblogs.com/WJZheng/p/11394569.html