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 9f452a9 commit e1c705dCopy full SHA for e1c705d
longest-increasing-subsequence/wogha95.js
@@ -0,0 +1,28 @@
1
+/**
2
+ * TC: O(N^2)
3
+ * SC: O(N)
4
+ * N: nums.length
5
+ */
6
+
7
8
+ * @param {number[]} nums
9
+ * @return {number}
10
11
+var lengthOfLIS = function (nums) {
12
+ // 각자 스스로는 최소 1의 lengthOfLIS를 가짐
13
+ const longestLength = new Array(nums.length).fill(1);
14
15
+ // nums배열의 right까지 원소들 중 lengthOfLIS를 저장
16
+ for (let right = 1; right < nums.length; right++) {
17
+ for (let left = 0; left < right; left++) {
18
+ if (nums[left] < nums[right]) {
19
+ longestLength[right] = Math.max(
20
+ longestLength[right],
21
+ longestLength[left] + 1
22
+ );
23
+ }
24
25
26
27
+ return Math.max(...longestLength);
28
+};
0 commit comments