485.max-consecutive-ones.go 218 B

1234567891011121314151617
  1. func findMaxConsecutiveOnes(nums []int) (max int) {
  2. cnt := 0
  3. for _, i := range nums {
  4. if i == 1 {
  5. cnt++
  6. } else {
  7. if max < cnt {
  8. max = cnt
  9. }
  10. cnt = 0
  11. }
  12. }
  13. if max < cnt {
  14. max = cnt
  15. }
  16. return
  17. }