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

  • 0
    class Solution:
    # @param {integer[]} nums
    # @return {integer[][]}
    def permuteUnique(self, nums):
        if len(nums)<2:
            return [nums]
        pre ='a'
        result =[]
        for i in range(len(nums)):
            if nums[i]!=pre:
                for y in self.permuteUnique(nums[:i]+nums[i+1:]):
                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.