Skip to content

Instantly share code, notes, and snippets.

@nleiva
Created February 25, 2018 02:13
Show Gist options
  • Save nleiva/ff3801d1e6ef2275f558d53ae5316193 to your computer and use it in GitHub Desktop.
Save nleiva/ff3801d1e6ef2275f558d53ae5316193 to your computer and use it in GitHub Desktop.
func findMaxConsecutiveOnes(nums []int) int {
total := 0
max := 0
for i := 0; i < len(nums); i++ {
if nums[i] == 1 {
total++
if total > max {
max = total
}
} else {
total = 0
}
}
return max
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment