Skip to content

Commit aede710

Browse files
authored
Merge pull request neetcode-gh#1698 from a93a/300
Create 0300-longest-increasing-subsequence.kt
2 parents d6beccd + f50c6a0 commit aede710

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun lengthOfLIS(nums: IntArray): Int {
3+
val dp = IntArray(nums.size){1}
4+
for(i in nums.size-1 downTo 0){
5+
for(j in i+1 until nums.size){
6+
if(nums[i] < nums[j]){
7+
dp[i] = maxOf(dp[i], 1 + dp[j])
8+
}
9+
}
10+
}
11+
var max = 0
12+
for(n in dp)
13+
max = maxOf(max, n)
14+
return max
15+
}
16+
}

0 commit comments

Comments
 (0)