Max Consecutive Ones


  • 0
    V
    class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
            int count = 0, result = 0;
            
            for(int i=0; i<nums.length; i++) {
                if(nums[i] == 0)
                    count = 0;
                else {
                    count++;
                    result = Math.max(count, result);
                }
            }
            return result;
        }
    }
    

Log in to reply
 

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