leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1208.cpp (454B)
0 class Solution { 1 public: 2 int equalSubstring(const string &s, const string &t, const int maxCost) const { 3 const int n = size(s); 4 int res = 0, total = 0; 5 6 for (int i = 0, j = 0; i < n; i++) { 7 total += abs(s[i] - t[i]); 8 while (maxCost < total) { 9 total -= abs(s[j] - t[j]); 10 j++; 11 } 12 res = max(res, i - j + 1); 13 } 14 15 return res; 16 } 17 };