Skip to content

Commit 1cc943a

Browse files
committed
[Leo] 12th Week solutions
1 parent 74e04c9 commit 1cc943a

File tree

1 file changed

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

1 file changed

+28
-0
lines changed

longest-increasing-subsequence/Leo.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def lengthOfLIS(self, nums: List[int]) -> int:
3+
arr = [nums.pop(0)]
4+
5+
for n in nums:
6+
if n > arr[-1]:
7+
arr.append(n)
8+
else:
9+
arr[bisect_left(arr, n)] = n
10+
11+
return len(arr)
12+
13+
## TC: O(nlogn) SC: O(n)
14+
15+
# if not nums:
16+
# return 0
17+
18+
# n = len(nums)
19+
# LIS = [1] * n
20+
21+
# for i in range(1, n):
22+
# for j in range(i):
23+
# if nums[i] > nums[j]:
24+
# LIS[i] = max(LIS[i], 1 + LIS[j])
25+
26+
# return max(LIS)
27+
28+
## DP solution: TC: O(n^2) O(n)

0 commit comments

Comments
 (0)