Java | Sliding Window | 15 lines | Clean code
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public int equalSubstring(String s, String t, int maxCost) {\n    var len = 0;\n    var cost = 0;\n    var i = 0;\n    var j = 0;\n\n    while (j < s.length()) {\n      if (cost <= maxCost) {\n        cost += Math.abs(s.charAt(j) - t.charAt(j));\n        j++;\n      }\n      while (cost > maxCost) {\n        cost -= Math.abs(s.charAt(i) - t.charAt(i));\n        i++;\n      }\n      len = Math.max(len, j-i);\n    }\n    return len;\n  }\n}\n```\nIf you like my solution, please upvote it!
['String', 'Sliding Window', 'Java']