java O(n) solution


  • 0
    L
    public int findMaxConsecutiveOnes(int[] nums) {
            int res = 0, temp = 0;
            for(Integer num : nums){
                temp = (num == 1) ? temp+1 : 0;
                res = Math.max(res,temp);
            }
            return res;
    }
    

Log in to reply
 

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