Skip to content

Commit b7f13bb

Browse files
committed
longest-increasing-subsequence solution
1 parent d91c9cc commit b7f13bb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param nums - ์ •์ˆ˜ ๋ฐฐ์—ด
3+
* @returns - ์—„๊ฒฉํ•˜๊ฒŒ ์ฆ๊ฐ€ํ•˜๋Š” ์š”์†Œ์˜ ๊ธธ์ด ๋ฐ˜ํ™˜
4+
*/
5+
function lengthOfLIS(nums: number[]): number {
6+
const arr: number[] = Array.from({ length: nums.length }, () => 1);
7+
let maxLen = 1;
8+
for (let i = 1; i < nums.length; i++) {
9+
for (let j = 0; j < i; j++) {
10+
if (nums[i] > nums[j]) {
11+
arr[i] = Math.max(arr[i], arr[j] + 1);
12+
}
13+
}
14+
maxLen = Math.max(maxLen, arr[i]);
15+
}
16+
17+
return maxLen;
18+
}
19+
20+
const nums = [0, 1, 0, 3, 2, 3];
21+
lengthOfLIS(nums);
22+
23+

0 commit comments

Comments
ย (0)