C++ Sliding Window (+ Cheat Sheet)
See my latest update in repo LeetCode\n\n## Solution 1. Sliding Window\n\nCheck out "C++ Maximum Sliding Window Cheatsheet Template!".\n\nShrinkable Sliding Win
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Sliding Window\n\nCheck out "[C++ Maximum Sliding Window Cheatsheet Template!](https://leetcode.com/problems/frequency-of-the-most-frequent-element/discuss/1175088/C%2B%2B-Maximum-Sliding-Window-Cheatsheet-Template!)".\n\nShrinkable Sliding Window:\n\n```cpp\n// OJ: https://leetcode.com/problems/get-equal-substrings-within-budget/\n// Author: github.com/lzl124631x\n// Time: O(N)\n// Space: O(1)\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n        int i = 0, j = 0, N = s.size(), cost = 0, ans = 0;\n        for (; j < N; ++j) {\n            cost += abs(s[j] - t[j]);\n            for (; cost > maxCost; ++i) cost -= abs(s[i] - t[i]);\n            ans = max(ans, j - i + 1);\n        }\n        return ans;\n    }\n};\n```\n\nNon-shrinkable Sliding Window:\n\n```cpp\n// OJ: https://leetcode.com/problems/get-equal-substrings-within-budget/\n// Author: github.com/lzl124631x\n// Time: O(N)\n// Space: O(1)\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n        int i = 0, j = 0, N = s.size(), cost = 0;\n        for (; j < N; ++j) {\n            cost += abs(s[j] - t[j]);\n            if (cost > maxCost) {\n                cost -= abs(s[i] - t[i]);\n                ++i;\n            }\n        }\n        return j - i;\n    }\n};\n```\n
[]