// 包含输入输入输出 #include<iostream> (5488)#include<vector> #include<algorithm> using namespace std; // 滑动窗口算法 int maxSlideWindow(vector<int> nums) { int left = 0, right = 0; int count = 0; int size = nums.size(); int res = 0; while (right < size) { count += nums[right] == 0; while (count > 1) { count -= nums[left] == 0; left++; } res = max(res, right - left + 1); right++; } return res - 1; } // 主函数 int main() { int count = 0; cin >> count; vector<vector<int>> nums; while (count--) { int signlCount = 0; cin >> signlCount; int temp = 0; vector<int> nums1; while (signlCount--) { cin >> temp; nums1.push_back(temp); } nums.push_back(nums1); } int length = nums.size(); for (auto & num : nums) { int res = maxSlideWindow(num); cout << res << " "; } cout << endl; //system("pause"); return 0; }
点赞 评论

相关推荐

三年之期已到我的offer快到碗里来:9硕都比不上9本
点赞 评论 收藏
分享
牛客网
牛客企业服务