Java 11ms short


  • 0
    V
        public int findMaxConsecutiveOnes(int[] nums) 
        {
            int q = 0, k = 1, maxCnt = 0, prev = -1, i = 0;
            for(i = 0; i < nums.length; i++)
            {
                if(nums[i] == 1)
                    continue;
                if(k == 1)
                {
                    q = i;
                    k--;
                    continue;
                }
                maxCnt = Math.max(maxCnt, i - 1 - prev);
                prev = q;
                q = i;
            }
            return Math.max(maxCnt, i - 1 - prev);
        }

Log in to reply
 

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