We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 74e04c9 commit 1cc943aCopy full SHA for 1cc943a
longest-increasing-subsequence/Leo.py
@@ -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