Sharing my 5 line python code

  • 0

    Just insert before same num

    def permuteUnique(self, nums):
        ans, pre = [[]], None
        for level, num in enumerate(sorted(nums)):
            ans, pre = [anslist[:i]+[num]+anslist[i:] for anslist in ans for i in xrange(anslist.index(pre)+1 if pre==num else level+1)], num
        return ans

Log in to reply

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