Files
LeetCode-Go/leetcode/0485.Max-Consecutive-Ones/485. Max Consecutive Ones.go
2020-08-11 23:46:26 +08:00

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
}