leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1004.cpp (368B)
0 class Solution { 1 public: 2 int longestOnes(const vector<int> &nums, int k) { 3 int maxi = 0, left = 0; 4 for (int i = 0; i < nums.size(); i++) { 5 maxi = max(maxi, i - left); 6 if (!nums[i]) k--; 7 while (k < 0) 8 if (!nums[left++]) k++; 9 } 10 return max(maxi, (int)nums.size() - left); 11 } 12 };