Skip to content

Commit 0637f87

Browse files
authored
334. Increasing Triplet Subsequence
1 parent 5f10498 commit 0637f87

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

334.IncreasingTripletSubsequence.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun increasingTriplet(nums: IntArray): Boolean {
3+
var firstSmallest = Int.MAX_VALUE
4+
var secondSmallest = Int.MAX_VALUE //larger than first
5+
for(num in nums){
6+
if(num <= firstSmallest){
7+
firstSmallest = num
8+
} else if(num <= secondSmallest){
9+
secondSmallest = num
10+
} else {
11+
return true
12+
}
13+
}
14+
return false
15+
}
16+
}

0 commit comments

Comments
 (0)