Skip to content

Commit b3e9d4b

Browse files
committed
solve: longest increasing subsequence
1 parent cfe4452 commit b3e9d4b

File tree

1 file changed

+19
-0
lines changed
  • longest-increasing-subsequence

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import bisect
2+
from typing import List
3+
4+
5+
class Solution:
6+
def lengthOfLIS(self, nums: List[int]) -> int:
7+
lis = []
8+
9+
for num in nums:
10+
# num이 왼쪽에 삽입될 수 있는 위치
11+
position = bisect.bisect_left(lis, num)
12+
13+
# num이 lis에 있는 모든 요소 보다 크다
14+
if position == len(lis):
15+
lis.append(num)
16+
else:
17+
lis[position] = num
18+
19+
return len(lis)

0 commit comments

Comments
 (0)