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 0060e06 commit 1c75461Copy full SHA for 1c75461
longest-increasing-subsequence/krokerdile.js
@@ -0,0 +1,23 @@
1
+// Time: O(n log n), Space: O(n)
2
+function lengthOfLIS(nums) {
3
+ const tails = [];
4
+
5
+ for (const num of nums) {
6
+ let left = 0, right = tails.length;
7
8
+ // 이진 탐색: tails에서 num이 들어갈 최소 위치 찾기
9
+ while (left < right) {
10
+ const mid = Math.floor((left + right) / 2);
11
+ if (tails[mid] < num) {
12
+ left = mid + 1;
13
+ } else {
14
+ right = mid;
15
+ }
16
17
18
+ // left는 삽입 위치
19
+ tails[left] = num;
20
21
22
+ return tails.length;
23
+}
0 commit comments