Simple solution by using lambda expression

  • 1
    class Solution:
        # @param {integer[]} nums
        # @return {integer[][]}
        def permuteUnique(self, nums):
            def replace(ls, integer):
                lst = list(ls)
                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

    This is absolutely beautiful!

Log in to reply

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