Skip to content

Commit adcc891

Browse files
authored
[ PS ] : Longest Increasing Subsequence
1 parent f94110e commit adcc891

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)