Simple solution by using lambda expression


  • 1
    J
    class Solution:
        # @param {integer[]} nums
        # @return {integer[][]}
        def permuteUnique(self, nums):
            def replace(ls, integer):
                lst = list(ls)
                lst.remove(integer)
                return lst
    
            f = lambda s: [s] if (len(s) == 1) else [[x] + y for x in set(s) for y in f(replace(s, x))]
            
            return f(nums)

  • 0
    M

    This is absolutely beautiful!


Log in to reply
 

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