给定一个没有重复数字的序列,返回其所有可能的全排列。
示例:
输入: [1,2,3] 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]
题目标签:Backtracking
题目链接:LeetCode / LeetCode中国
用Python的话,可以直接用内建的itertools模块,一行搞定,宛如开挂。
| Language | Runtime | Memory |
|---|---|---|
| python3 | 76 ms | N/A |
class Solution:
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
return list(itertools.permutations(nums))