[Java] Simple Sliding Window, 10 lines code, Time O(N), Space O(1)
java\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        int l = 0, r = 0, n = s.length(), cost = 0, ans = 0;\n        
```java\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        int l = 0, r = 0, n = s.length(), cost = 0, ans = 0;\n        while (r < n) {\n            cost += Math.abs(s.charAt(r) - t.charAt(r));\n             while (cost > maxCost) {\n                cost -= Math.abs(s.charAt(l) - t.charAt(l));\n                l++;\n            }\n            ans = Math.max(ans, r - l + 1);\n            r++;\n        }\n        return ans;\n    }\n}\n```
['Java']