Created
July 24, 2018 02:57
-
-
Save luojiyin1987/1a5a572a10385f55cab2cf7701bbffcc to your computer and use it in GitHub Desktop.
Max Consecutive Ones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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