luoheng
10/7/2019 - 3:55 AM

findMaxConsecutiveOnes

func findMaxConsecutiveOnes(nums []int) int {
    s, max := 0, 0
    for _, n := range nums {
        if n == 0 {
            if s > max {
                max = s
            }
            s = 0
        } else {
            s++
        }
    }
    if s > max {
        return s
    }
    return max
}