java.lang.Object
g1201_1300.s1208_get_equal_substrings_within_budget.Solution

public class Solution extends Object
1208 - Get Equal Substrings Within Budget.<p>Medium</p> <p>You are given two strings <code>s</code> and <code>t</code> of the same length and an integer <code>maxCost</code>.</p> <p>You want to change <code>s</code> to <code>t</code>. Changing the <code>i<sup>th</sup></code> character of <code>s</code> to <code>i<sup>th</sup></code> character of <code>t</code> costs <code>|s[i] - t[i]|</code> (i.e., the absolute difference between the ASCII values of the characters).</p> <p>Return <em>the maximum length of a substring of</em> <code>s</code> <em>that can be changed to be the same as the corresponding substring of</em> <code>t</code> <em>with a cost less than or equal to</em> <code>maxCost</code>. If there is no substring from <code>s</code> that can be changed to its corresponding substring from <code>t</code>, return <code>0</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcd&rdquo;, t = &ldquo;bcdf&rdquo;, maxCost = 3</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> &ldquo;abc&rdquo; of s can change to &ldquo;bcd&rdquo;. That costs 3, so the maximum length is 3.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcd&rdquo;, t = &ldquo;cdef&rdquo;, maxCost = 3</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> Each character in s costs 2 to change to character in t, so the maximum length is 1.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcd&rdquo;, t = &ldquo;acde&rdquo;, maxCost = 0</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> You cannot make any change, so the maximum length is 1.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>t.length == s.length</code></li> <li><code>0 <= maxCost <= 10<sup>6</sup></code></li> <li><code>s</code> and <code>t</code> consist of only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • equalSubstring

      public int equalSubstring(String s, String t, int maxCost)