Skip to content

Commit 45c944e

Browse files
committed
[WEEK6](gmlwls96) Longest Increasing Subsequence
1 parent 2826f54 commit 45c944e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
// 시간 : O(n), 공간 : O(n)
3+
// nums를 조회하면서 이전값과 비교하여
4+
// 더 증가하였으면 : 이전 카운트 +1
5+
// 같거나 작으면 : 이전 카운트값
6+
fun lengthOfLIS(nums: IntArray): Int {
7+
val count = IntArray(nums.size)
8+
count[0] = 1
9+
var prev = nums[0]
10+
for (i in 1 until nums.size){
11+
if(prev < nums[i]){
12+
count[i] += count[i-1] +1
13+
}else {
14+
count[i] = count[i-1]
15+
}
16+
prev = nums[i]
17+
}
18+
return count.last()
19+
}
20+
}

0 commit comments

Comments
 (0)