Simply modifying permutations 1 adding one condition where current number equals the previous one


  • 0
    W
    class Solution:
    # @param {integer[]} nums
    # @return {integer[][]}
    def permuteUnique(self, nums):
        if len(nums)<2:
            return [nums]
        pre ='a'
        result =[]
        nums.sort()
        for i in range(len(nums)):
            if nums[i]!=pre:
                for y in self.permuteUnique(nums[:i]+nums[i+1:]):
                    result.append([nums[i]]+y)
                pre = nums[i]
        return result

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.