Python solution with generator


  • 0
    B
        def permute(self, nums):
    
            def permutations(nums):
                if not nums:
                    yield []
                for n in nums:
                    for permut in permutations([i for i in nums if i != n]):
                        yield [n] + permut
                        
            return [permut for permut in permutations(nums)]
    

Log in to reply
 

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