WillWang-X
7/12/2017 - 10:09 PM

Increasing_Subsequences.py

class Solution(object):
    def findSubsequences(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        dp = set()
        for n in nums:
            for y in list(dp):
                if n >= y[-1]:
                    dp.add(y + (n,))
            dp.add((n,))
        return list(e for e in dp if len(e) > 1)
 
'''
print Solution().findSubsequences([4, 6, 7, 7])

set([(4,)])
set([(6,), (4, 6), (4,)])
set([(4, 7), (6, 7), (4, 6), (4,), (6,), (7,), (4, 6, 7)])
set([(4, 7), (6, 7), (4, 6), (7, 7), (4,), (6,), (7,), (6, 7, 7), (4, 6, 7), (4, 6, 7, 7), (4, 7, 7)])
[(4, 7), (6, 7), (4, 6), (7, 7), (6, 7, 7), (4, 6, 7), (4, 6, 7, 7), (4, 7, 7)]
'''