美文网首页
46. 全排列

46. 全排列

作者: 江北_c2b1 | 来源:发表于2018-09-13 19:05 被阅读0次

    class Solution(object):

    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        self.res = []
        sub = []
        self.dfs(nums,sub)
        return self.res
    
    def dfs(self, Nums, subList):
        if len(subList) == len(Nums):
            #print res,subList
            self.res.append(subList[:])
        for m in Nums:
            if m in subList:
                continue
            subList.append(m)
            self.dfs(Nums,subList)
            subList.remove(m)

    相关文章

      网友评论

          本文标题:46. 全排列

          本文链接:https://www.haomeiwen.com/subject/okjggftx.html