Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created July 24, 2018 02:57
Show Gist options
  • Save luojiyin1987/1a5a572a10385f55cab2cf7701bbffcc to your computer and use it in GitHub Desktop.
Save luojiyin1987/1a5a572a10385f55cab2cf7701bbffcc to your computer and use it in GitHub Desktop.
Max Consecutive Ones
func findMaxConsecutiveOnes(nums []int) int {
max := 0
count := 0
for i := range nums{
if nums[i] == 1 {
count++
} else if nums[i] == 0 {
if max < count {
max = count
}
count = 0
}
}
if max < count {
max = count
}
return max
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment