Created
February 25, 2018 02:13
-
-
Save nleiva/ff3801d1e6ef2275f558d53ae5316193 to your computer and use it in GitHub Desktop.
Max Consecutive Ones (485) from https://leetcode.com/problems/max-consecutive-ones/description/.
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 { | |
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