Skip to content

Commit 6b7b619

Browse files
committed
add solution: longest-increasing-subsequence
1 parent 2b976cd commit 6b7b619

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const lengthOfLIS = (nums) => {
6+
const dp = new Array(nums.length).fill(1);
7+
8+
for (let i = 1; i < nums.length; i++) {
9+
for (let j = 0; j < i; j++) {
10+
if (nums[j] < nums[i]) {
11+
dp[i] = Math.max(dp[i], dp[j] + 1);
12+
}
13+
}
14+
}
15+
16+
return Math.max(...dp);
17+
};

0 commit comments

Comments
 (0)