Skip to content

Commit 444ec91

Browse files
authored
Update 0300-longest-increasing-subsequence.kt
1 parent 4e4dd8c commit 444ec91

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
class Solution {
22
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]){
3+
val dp = IntArray(nums.size) {1}
4+
5+
for (i in nums.size-1 downTo 0) {
6+
for (j in i + 1 until nums.size) {
7+
if (nums[i] < nums[j]) {
78
dp[i] = maxOf(dp[i], 1 + dp[j])
89
}
910
}
1011
}
11-
var max = 0
12-
for(n in dp)
13-
max = maxOf(max, n)
14-
return max
12+
13+
return dp.max()!!
1514
}
1615
}

0 commit comments

Comments
 (0)