Skip to content

Instantly share code, notes, and snippets.

@willwangcc
Created July 12, 2017 22:09
Show Gist options
  • Save willwangcc/b277fe0a4a0e525990ba94f394e2d25a to your computer and use it in GitHub Desktop.
Save willwangcc/b277fe0a4a0e525990ba94f394e2d25a to your computer and use it in GitHub Desktop.
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)]
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment