class Solution {
public:
int longestOnes(vector<int>& A, int K) {
int n = A.size();
int left = 0;
int right = 0;
int max_cnt = 0;
int map[2] = {
0 };
int res = 0;
while (right < n)
{
map[A[right]]++;
max_cnt = max(max_cnt, map[1]);
if (right - left + 1 > max_cnt + K)
{
map[A[left]]--;
left++;
}
else
{
res = max(res, right - left + 1);
}
right++;
}
return res;
}
};
LeetCode1004. 最大连续1的个数 III
猜你喜欢
转载自blog.csdn.net/qq_32862515/article/details/109235645
今日推荐
周排行