[java] simple solution based on two pointers
\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        if(maxCost < 0 || s == null || t == null || s.length() != t.length
```\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        if(maxCost < 0 || s == null || t == null || s.length() != t.length() || s.length() == 0) {\n            return 0;\n        }\n        \n        int[] diffs = new int[s.length()];\n        int left = 0, cost = 0, maxLen = 0;\n        for(int i = 0; i < s.length(); ++i) {\n            diffs[i] = Math.abs((int)s.charAt(i) - (int)t.charAt(i));\n            if(diffs[i] > maxCost) {\n                left = i+1;\n                cost = 0;\n            } else {\n                cost += diffs[i];\n\t\t\t\t// can use binary search to speed it up\n                while(left <= i && cost > maxCost) {\n                    cost -= diffs[left];\n                    ++left;\n                }\n            }\n            \n            maxLen = Math.max(maxLen, i - left + 1);\n        }\n        \n        return maxLen;\n    }\n}\n```
[]