class Solution {
public int equalSubstring(String s, String t, int maxCost) {
int left = 0, right =0;
int sum = 0;
int res = 0;
// 构造窗口
while (right < s.length()) {
sum += Math.abs(s.charAt(right) - t.charAt(right));
right++;
// 窗口构造完成,这时候要根据条件当前的窗口调整窗口大小
while (sum > maxCost) {
sum -= Math.abs(s.charAt(left) - t.charAt(left));
left++;
}
// 记录此时窗口的大小
res = Math.max(res, right -left);
}
return res;
}
}