Skip to content

Commit 65d0601

Browse files
committed
longest increasing subsequence solution
1 parent 612bf66 commit 65d0601

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import List
2+
class Solution:
3+
def lengthOfLIS(self, nums: List[int]) -> int:
4+
def binary_search(target):
5+
left, right = 0, len(result)
6+
7+
while left < right:
8+
mid = (left + right) // 2
9+
if result[mid] < target:
10+
left = mid + 1
11+
else:
12+
right = mid
13+
return left
14+
15+
result = []
16+
17+
for num in nums:
18+
idx = binary_search(num)
19+
if idx == len(result):
20+
result.append(num)
21+
else:
22+
result[idx] = num
23+
24+
return len(result)
25+
26+
27+

0 commit comments

Comments
 (0)