250x250
반응형
Notice
Recent Posts
Recent Comments
Link
N
(Leet Code JS)Longest Increasing Subsequence 본문
728x90
반응형
https://leetcode.com/problems/longest-increasing-subsequence/
/**
* @param {number[]} nums
* @return {number}
*/
var lengthOfLIS = function(nums) {
const length = nums.length;
const dp = Array.from({length}, () => 0);
let answer = 0;
for(let i = 0; i < length; i++){
if(dp[i] === 0){
dp[i] = 1;
}
for(let j = 0; j < length; j++){
if(nums[j] < nums[i]){
if(dp[i] < dp[j] + 1){
dp[i] = dp[j] + 1;
}
}
}
answer = Math.max(answer, dp[i]);
}
return answer;
};
728x90
반응형
'Leet Code 알고리즘' 카테고리의 다른 글
(Leet Cods JS)2348. Number of Zero-Filled Subarrays (0) | 2023.03.26 |
---|---|
(Leet Code JS)Capacity To Ship Packages Within D Days (0) | 2023.02.25 |
(Leet Code JS)Diagonal Traverse (0) | 2022.07.30 |
(Leet Code JS)Game of Life (0) | 2022.07.30 |
(Leet Code JS)Candy (0) | 2022.07.10 |