aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/deadmarshal/go/ch1.go
blob: af4cd5e8639de6d7286ef5bd1c7ff48197a5b4b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import (
	"fmt"
)

func consecutiveOne(arr []int) int {
	count, res := 0, 0
	for _, e := range arr {
		if e == 1 {
			count++
		} else {
			res = max(res, count)
			count = 0
		}
	}
	return max(count, res)
}

func main() {
	fmt.Println(consecutiveOne([]int{0, 1, 1, 0, 1, 1, 1}))
	fmt.Println(consecutiveOne([]int{0, 0, 0, 0}))
	fmt.Println(consecutiveOne([]int{1, 0, 1, 0, 1, 1}))
}