-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindDecks.py
30 lines (25 loc) · 962 Bytes
/
FindDecks.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
import bisect
class Solution:
def findNumberOfLIS(self, nums):
if not nums: return 0
decks, ends_decks, paths = [], [], []
for num in nums:
deck_idx = bisect.bisect_left(ends_decks, num)
print("num", num, "deck_idx", deck_idx)
n_paths = 1
if deck_idx > 0:
l = bisect.bisect(decks[deck_idx - 1], -num)
n_paths = paths[deck_idx - 1][-1] - paths[deck_idx - 1][l]
if deck_idx == len(decks):
decks.append([-num])
ends_decks.append(num)
paths.append([0, n_paths])
else:
decks[deck_idx].append(-num)
ends_decks[deck_idx] = num
paths[deck_idx].append(n_paths + paths[deck_idx][-1])
for deck in decks:
print(deck)
return paths[-1][-1]
sol = Solution()
print("result", sol.findNumberOfLIS([1,3,5,4,7,10,8,2,8]))