diff --git a/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1208.java b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1208.java new file mode 100644 index 0000000..dee5416 --- /dev/null +++ b/src/main/java/com/cool/ling_cha_mount/sliding_windows/Num1208.java @@ -0,0 +1,35 @@ +package com.cool.ling_cha_mount.sliding_windows; + +import org.junit.Test; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/10/18/12:28 + * @Description: 1208. 尽可能使字符串相等 + * Hard 2 + * Score 1497 + */ +public class Num1208 { + public int equalSubstring(String s, String t, int maxCost) { + int curCost = maxCost; + int left = 0; + int res = 0; + char[] sChar = s.toCharArray(); + char[] tChar = t.toCharArray(); + for (int i = 0; i < sChar.length; i++) { + curCost -= Math.abs(sChar[i] - tChar[i]); + while (curCost < 0) { + curCost+=Math.abs(sChar[left]-tChar[left++]); + } + res = Math.max(res, i - left + 1); + } + return res; + } + + @Test + public void test() { + equalSubstring("krrgw", "zjxss", 19); + } +}