java.lang.Object
g0401_0500.s0424_longest_repeating_character_replacement.Solution

public class Solution extends Object
424 - Longest Repeating Character Replacement.<p>Medium</p> <p>You are given a string <code>s</code> and an integer <code>k</code>. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most <code>k</code> times.</p> <p>Return <em>the length of the longest substring containing the same letter you can get after performing the above operations</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;ABAB&rdquo;, k = 2</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> Replace the two &rsquo;A&rsquo;s with two &rsquo;B&rsquo;s or vice versa.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;AABABBA&rdquo;, k = 1</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> Replace the one &lsquo;A&rsquo; in the middle with &lsquo;B&rsquo; and form &ldquo;AABBBBA&rdquo;. The substring &ldquo;BBBB&rdquo; has the longest repeating letters, which is 4.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s</code> consists of only uppercase English letters.</li> <li>`0 <= k <= s.length</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • characterReplacement

      public int characterReplacement(String s, int k)