You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution {
public:intlongestOnes(vector<int>& nums, int k) {
int left = 0;
int max_len = 0;
int zero_count = 0;
for (int right = 0; right < nums.size(); right++) {
if (nums[right] == 0) {
zero_count++;
}
while (zero_count > k) {
if (nums[left] == 0) {
zero_count--;
}
left++;
}
max_len = max(max_len, right - left + 1);
}
return max_len;
}
};
슬라이딩 윈도우 기법으로 풀이
왼쪽과 오른쪽 포인터의 움직임에서 다른 점은 2중 반복으로 0의 개수를 체크하는 부분
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: