-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path491.py
32 lines (32 loc) · 1.3 KB
/
491.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__________________________________________________________________________________________________
sample 228 ms submission
class Solution:
def findSubsequences(self, nums: List[int]) -> List[List[int]]:
# use a set to keep track for constant lookup
subs = {()}
for num in nums:
# keep adding new sequences in the set
subs |= {sub + (num,)
for sub in subs
if not sub or sub[-1] <= num}
# return the ones bigger than 1
return [sub for sub in subs if len(sub) >= 2]
__________________________________________________________________________________________________
sample 21096 kb submission
class Solution:
def findSubsequences(self, nums: 'List[int]') -> 'List[List[int]]':
ans = []
for num in nums:
cur = []
for sub in ans:
if sub[-1] < num:
cur.append(sub[:] + [num])
cur.append(sub)
elif sub[-1] == num:
cur.append(sub[:] + [num])
else:
cur.append(sub)
cur.append([num])
ans = cur
return [l for l in ans if len(l) > 1]
__________________________________________________________________________________________________