public int longestOnes(int[] nums, int k) {
// 1 -> 0
int ans = 0;
for (int left = 0, right = 0, count = 0; right < nums.length; right++) {
count += nums[right] == 0 ? 1 : 0;
while (count > k) {
count -= nums[left] == 0 ? 1 : 0;
left++;
}
ans = Math.max(ans, right - left + 1);
}
return ans;
}
https://leetcode-cn.com/problems/max-consecutive-ones-iii/
思路
刷15mins
刷5mins