Valid Parentheses @ LeetCode (Python)
Add Two Numbers @ LeetCode (Python)

Subsets II @ LeetCode (Python)

kitt posted @ 2014年2月13日 13:58 in LeetCode , 2819 阅读

看了此文, 如果是重复数字, 只扩展上一次的结果, 如果是不重复数字, 则扩展全部结果。

class Solution:
    # @param num, a list of integer
    # @return a list of lists of integer
    def subsetsWithDup(self, S):
        res = [[]]; preSet = []; preNum = -10**10
        S.sort()
        for i in S:
            oldSet = res[:] if i != preNum else preSet[:]
            preNum = i
            preSet = []
            for j in oldSet:
                res.append(j + [i])
                preSet.append(j + [i])
        return res

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter