mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
17 lines
273 B
Go
17 lines
273 B
Go
package leetcode
|
|
|
|
func findMaxConsecutiveOnes(nums []int) int {
|
|
maxCount, currentCount := 0, 0
|
|
for _, v := range nums {
|
|
if v == 1 {
|
|
currentCount++
|
|
} else {
|
|
currentCount = 0
|
|
}
|
|
if currentCount > maxCount {
|
|
maxCount = currentCount
|
|
}
|
|
}
|
|
return maxCount
|
|
}
|