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

Subsets II @ LeetCode (Python)

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

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

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
Avatar_small
mining cryptocurrenc 说:
2024年12月25日 00:09

I visit your blog regularly and recommend it to all of those who wanted to enhance their knowledge with ease


登录 *


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