Why does this attempt fail at test case 20?


  • 0
    2

    why does it fail test case 20?

    Output: 3323
    Expected: 2840

    public class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
            int counter = 0;
            int maxConsecutiveOnes = 0;
            
            for(int i = 0; i < nums.length; i++){
                if(nums[i] == 1){
                    counter+=1;
                }else{
                    // element == 0
                    
                    if(counter != 0 && counter > maxConsecutiveOnes){
                        maxConsecutiveOnes = counter;
                        counter = 0;
                    }
                }
            }
            
            if(counter > maxConsecutiveOnes){
                maxConsecutiveOnes = counter;
            }
            
            return maxConsecutiveOnes;
        }
    }
    

Log in to reply
 

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