Here's my Java code which has just beaten 100% submissions.


  • 0
    D

    I am happy : )

    public class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
            int n = nums.length;
            int max = 0, count = 0;
            int i = 0;
            while(i < n - max){
                if(nums[i] != 1){
                    i++;
                }else{
                    do{
                        count++;
                        i++;
                    }while((i < n) && (nums[i] == 1));
                    max = count>max? count: max;
                    count = 0;
                }
            }
            
            return max;
        }
    }
    

Log in to reply
 

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