javascript solution


  • 0
    Y

    var findMaxConsecutiveOnes = function(nums) {

    var nowArr=[]
    var now=1
      for(i=0;i<nums.length;i++){
       if(nums[0]==1){
        nowArr.push(1);
     }
     if(nums[0]==0){
      nowArr.push(0)
     }
     if(i>0){
      if(nums[i]!== nums[i-1]){
        now=1
        nowArr.push(now)
      }else{
        if(nums[i]==1){
           now++
           nowArr.push(now)
        }
    
      }
     }
    

    }
    return Math.max(...nowArr)
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.