47Permutations II

在46的基础上改改就能通过了

https://www.cnblogs.com/mangmangbiluo/p/10154417.html

    def permuteUnique(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        result = [[]]
        for i, num in enumerate(nums):
            result = [line[:j]+[num]+line[j:] for j in range(i+1) for line in result]
        result.sort()
        linetmp = None
        tmp = []
        for line in result:
            if line != linetmp:
                tmp.append(line)
            linetmp = line
        result = tmp
        return result

 

posted @ 2018-12-21 15:37  茫茫碧落  阅读(81)  评论(0编辑  收藏  举报