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 8382887 commit 36e7cf3Copy full SHA for 36e7cf3
longest-increasing-subsequence/gitsunmin.ts
@@ -0,0 +1,21 @@
1
+/**
2
+ * https://leetcode.com/problems/longest-increasing-subsequence
3
+ * time complexity : O(n)
4
+ * space complexity : O(n)
5
+ */
6
+function lengthOfLIS(nums: number[]): number {
7
+ const [head] = nums;
8
+ const basket = [head];
9
+
10
+ for (let i = 1; i < nums.length; i++) {
11
+ const current = nums[i];
12
+ let j = 0;
13
14
+ while (j < basket.length && basket[j] < current) j++;
15
16
+ if (j === basket.length) basket.push(current);
17
+ else basket[j] = current;
18
+ }
19
20
+ return basket.length;
21
+};
0 commit comments