-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
-
思路
- 滑动窗口
-
刷15mins
-
刷5mins
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;
}