Java beats 99%


  • 0
    L
    public class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
           // the 1 is always included by 0
            int start = -1; //record the start of 0
            int end = 0;//record the end of 0
            int max = 0; //record the max num of 1
            
            
            while(start<nums.length && end<nums.length){
            	//find the 0
    	        while(end<nums.length && nums[end]!=0){
    	        	end++;
    	        }
    	        if(end-start-1>max){
    	        	max = end-start-1;
    	        }
    	        start = end;
    	        end++;
            }
            return max;
        }
    }
    

  • 0
    L

    @liman657 great idea


Log in to reply
 

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