网址:https://leetcode.com/problems/max-consecutive-ones-iii/
参考:https://leetcode.com/problems/max-consecutive-ones-iii/discuss/247564/JavaC%2B%2BPython-Sliding-Window
- sliding window
- K -= (A[j] == 0);
- 注意判断条件
class Solution {
public:
int longestOnes(vector<int>& A, int K) {
int i = ;
int ans = ;
for(int j = ; j<A.size(); j++)
{
K -= (A[j] == );
if(K < )
{
K += (A[i] == );
i++;
}
ans = j - i + ;
}
return ans;
}
};