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 ef86fcc commit bd021c9Copy full SHA for bd021c9
longest-increasing-subsequence/JANGSEYEONG.js
@@ -0,0 +1,21 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number}
4
+ */
5
+var lengthOfLIS = function (nums) {
6
+ let sub = [nums[0]]; // 가장 첫번째 원소 일단 넣고 보기
7
+ for (const num of nums.slice(1)) {
8
+ if (num > sub[sub.length - 1]) {
9
+ // 수열의 마지막값보다 크면 무조건 추가
10
+ sub.push(num);
11
+ } else {
12
+ // 수열의 마지막값보다 작다면 이 숫자보다 큰 숫자들 중 가장 작은 숫자를 찾아서 교체
13
+ let i = 0;
14
+ while (sub[i] < num) {
15
+ i++;
16
+ }
17
+ sub[i] = num;
18
19
20
+ return sub.length;
21
+};
0 commit comments