My Java Solution beats 95%


  • 0
    R
    public int findMaxConsecutiveOnes(int[] nums) {
            if(nums.length == 0) return 0;
            int max = -1;
            int i = 0;
            int count = 0;
            while(i < nums.length){
                if(nums[i]!=1){
                    max = Math.max(max,count);
                    count = 0;
                }
                else{
                    count++;
                }
                i++;
            }
            return Math.max(count, max);
        }

Log in to reply
 

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