Skip to content

Commit

Permalink
3-최대부분증가수열
Browse files Browse the repository at this point in the history
  • Loading branch information
minbr0ther committed Feb 1, 2022
1 parent e463d6f commit 17b3a46
Showing 1 changed file with 22 additions and 0 deletions.
@@ -0,0 +1,22 @@
function solution(arr) {
let answer = 0;
let dy = Array.from({ length: arr.length }, () => 0);
dy[0] = 1;

for (let i = 1; i < arr.length; i++) {
let max = 0;

for (let j = i - 1; j >= 0; j--) {
if (arr[i] > arr[j] && dy[j] > max) {
max = dy[j];
}
}
dy[i] = max + 1;
answer = Math.max(answer, dy[i]);
}

return answer;
}

let arr = [5, 3, 7, 8, 6, 2, 9, 4];
console.log(solution(arr));

0 comments on commit 17b3a46

Please sign in to comment.