class Solution {
public:
int equalSubstring(string s, string t, int maxCost) {
int s_n = s.length();
if(!s_n) return 0;
queue<pair<int,int>> q;
int now = 0,answer = 0;
for(int i=0;i<s_n;i++){
q.emplace(i,abs(t[i]-s[i]));
now += abs(t[i]-s[i]);
if(now<=maxCost) answer = q.size()>answer?q.size():answer;
else {
while(now>maxCost){
auto [x,y] = q.front();
now -= y;
q.pop();
}
}
}
return answer;
}
};
放入队列顺序判断字符串即可。