Untitled
unknown
plain_text
a year ago
645 B
5
Indexable
class Solution {
public int longestOnes(int[] nums, int k) {
int left = 0, maxLength = 0, zeroCount = 0;
for (int right = 0; right < nums.length; ++right) {
if (nums[right] == 0) {
zeroCount++;
}
if (zeroCount > k) {
if (nums[left] == 0) {
zeroCount--;
}
left++;
}
// only if it is valid , also u can keep track of leftb & rightb
if(zeroCount<=k)
maxLength = Math.max(maxLength, right - left + 1);
}
return maxLength;
}
}
Editor is loading...
Leave a Comment