Skip to content

Instantly share code, notes, and snippets.

@LarrySul
Last active May 6, 2021 09:04
Show Gist options
  • Save LarrySul/440a563c353be79e0707325b3c794401 to your computer and use it in GitHub Desktop.
Save LarrySul/440a563c353be79e0707325b3c794401 to your computer and use it in GitHub Desktop.
Given a binary array nums, return the maximum number of consecutive 1's in the array.
class Solution {
function findMaxConsecutiveOnes($nums) {
$count = 0;
$consecutiveOnes = 0;
foreach($nums as $num){
if($num == 1){
$count +=1;
$consecutiveOnes = max($count, $consecutiveOnes);
}else{
$count = 0;
}
}
return $consecutiveOnes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment