class Solution { public: int longestOnes(vector<int>& nums, int k) { unordered_map<int,int> un_map; int sum = 0; int i = 0; int j = 0; for(j = 0; j < nums.size(); j++){ sum = sum + nums[j]; // 记录1的个数 if(j-i+1>sum+k){ // 如果当前窗口size大于可维护的窗口大小,收缩窗口 sum =sum -nums[i]; i++; } } return j-i; } };