Skip to content

Commit 938990f

Browse files
committed
longest-increasing-subsequence solved
1 parent 12924f4 commit 938990f

File tree

1 file changed

+16
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)