Skip to content

Commit e53c316

Browse files
committed
longest increasing subsequence solution
1 parent 036e221 commit e53c316

File tree

1 file changed

+14
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)