Skip to content

Commit 55cf613

Browse files
committed
feat: longest-increasing-subsequence
1 parent f18bb1c commit 55cf613

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 시간 복잡도 : O(nlogn)
2+
# 공간 복잡도 : O(n)
3+
# 문제 유형 : DP, Binary Search
4+
class Solution:
5+
def lengthOfLIS(self, nums: List[int]) -> int:
6+
dp = []
7+
for num in nums:
8+
if not dp or num > dp[-1]:
9+
dp.append(num)
10+
else:
11+
left, right = 0, len(dp) - 1
12+
while left < right:
13+
mid = left + (right - left) // 2
14+
if dp[mid] < num:
15+
left = mid + 1
16+
else:
17+
right = mid
18+
dp[right] = num
19+
return len(dp)
20+

0 commit comments

Comments
 (0)