Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1698 from a93a/300
Browse files Browse the repository at this point in the history
Create 0300-longest-increasing-subsequence.kt
  • Loading branch information
Ahmad-A0 authored Dec 29, 2022
2 parents d6beccd + f50c6a0 commit aede710
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions kotlin/0300-longest-increasing-subsequence.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
fun lengthOfLIS(nums: IntArray): Int {
val dp = IntArray(nums.size){1}
for(i in nums.size-1 downTo 0){
for(j in i+1 until nums.size){
if(nums[i] < nums[j]){
dp[i] = maxOf(dp[i], 1 + dp[j])
}
}
}
var max = 0
for(n in dp)
max = maxOf(max, n)
return max
}
}

0 comments on commit aede710

Please sign in to comment.