Last active
May 6, 2021 09:04
-
-
Save bigdevlarry/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.
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
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