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 f94110e commit adcc891Copy full SHA for adcc891
longest-increasing-subsequence/uraflower.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * 주어진 배열에서 가장 긴 증가하는 수열의 길이를 반환하는 함수
3
+ * @param {number[]} nums
4
+ * @return {number}
5
+ */
6
+const lengthOfLIS = function (nums) {
7
+ const dp = Array(nums.length).fill(1);
8
+
9
+ for (let i = 0; i < nums.length; i++) {
10
+ for (let j = 0; j < i; j++) {
11
+ if (nums[j] < nums[i])
12
+ dp[i] = Math.max(dp[j] + 1, dp[i]);
13
+ }
14
15
16
+ return Math.max(...dp);
17
+};
18
19
+// 시간복잡도: O(n^2)
20
+// 공간복잡도: O(n)
0 commit comments