We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2826f54 commit 45c944eCopy full SHA for 45c944e
longest-increasing-subsequence/gmlwls.kt
@@ -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