Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int longestOnes(vector<int>& A, int K) {
- int count, left, right, n=A.size(), ans;
- count = ans = 0;
- for(left=0,right=0; right<n; right++){
- if(A[right] == 0) count++;
- while(count > K)
- if(A[left++] == 0) count--;
- ans = max(ans, right-left+1);
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement