Friday, September 12, 2014

Leetcode: Subsets II @Python

class Solution:
    # @param num, a list of integer
    # @return a list of lists of integer
    def subsetsWithDup(self, S):
        res = [[]]
        for e in sorted(S):
            res = res+[l+[e] for l in res if l+[e] not in res]
        return res

No comments :

Post a Comment