Skip to content

Commit e7323b3

Browse files
committed
485/kt
1 parent 3a149dd commit e7323b3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

485.max-consecutive-ones.0.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @lc app=leetcode id=485 lang=kotlin
3+
*
4+
* [485] Max Consecutive Ones
5+
*/
6+
class Solution_findMaxConsecutiveOnes_0 {
7+
fun findMaxConsecutiveOnes(nums: IntArray): Int {
8+
val mums = nums.dropWhile { it != 1 }
9+
10+
if (mums.size == 0) return 0
11+
12+
var maxCount = 1
13+
var currCount = 1
14+
mums.drop(1).forEach {
15+
if (it == 1) {
16+
currCount++
17+
} else {
18+
currCount = 0
19+
}
20+
if (currCount > maxCount) {
21+
maxCount = currCount
22+
}
23+
}
24+
25+
return maxCount
26+
}
27+
}

0 commit comments

Comments
 (0)