leetcode力扣46. 全排列

给定一个没有重复数字的序列,返回其所有可能的全排列。

示例:

输入: [1,2,3]
输出:
[
  [1,2,3],
  [1,3,2],
  [2,1,3],
  [2,3,1],
  [3,1,2],
  [3,2,1]
]

python内置的一个函数

class Solution(object):
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        res = itertools.permutations(nums,len(nums))

        return res
发布了302 篇原创文章 · 获赞 161 · 访问量 49万+

猜你喜欢

转载自blog.csdn.net/qq_32146369/article/details/104106144
今日推荐