LeetCode 1208. Get Equal Substrings Within Budget — JavaScript
Published in
May 29, 2024
領500元現金了嗎? 點選我的連結成功開樂天帳戶+登入樂天網銀APP,拿500元現金! 樂天帳戶好康在這 : · 使用行動支付5次,享次月活儲年息1.35%存額無上限 · VIP享每月免費跨提/轉共16次 · 提領日幣手續費優惠8次/月 (推薦序號: JGONGL)
https://www.rakuten-bank.com.tw/s/R775
var equalSubstring = function(s, t, maxCost) {
let n = s.length, start = 0, currentCost = 0, maxLength = 0;
for (let end = 0; end < n; end++) {
currentCost += Math.abs(s.charCodeAt(end) - t.charCodeAt(end));
while (currentCost > maxCost) {
currentCost -= Math.abs(s.charCodeAt(start) - t.charCodeAt(start));
start++;
}
maxLength = Math.max(maxLength, end - start + 1);
}
return maxLength;
};
sliding window