Java sliding window
\n    public int equalSubstring(String s, String t, int maxCost) {\n        int res = 0, n = s.length();\n        for (int r = 0, l = 0, diff = 0; r < n; r++) {
```\n    public int equalSubstring(String s, String t, int maxCost) {\n        int res = 0, n = s.length();\n        for (int r = 0, l = 0, diff = 0; r < n; r++) {\n            diff += Math.abs(s.charAt(r) - t.charAt(r));\n            while (diff > maxCost) {\n                diff -= Math.abs(s.charAt(l) - t.charAt(l++));\n            }\n            res = Math.max(r - l + 1, res);\n        }\n        return res;\n    }\n```
[]