Class Solution
java.lang.Object
g1101_1200.s1156_swap_for_longest_repeated_character_substring.Solution
1156 - Swap For Longest Repeated Character Substring.<p>Medium</p>
<p>You are given a string <code>text</code>. You can swap two of the characters in the <code>text</code>.</p>
<p>Return <em>the length of the longest substring with repeated characters</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> text = “ababa”</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> We can swap the first ‘b’ with the last ‘a’, or the last ‘b’ with the first ‘a’. Then, the longest repeated character substring is “aaa” with length 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> text = “aaabaaa”</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> Swap ‘b’ with the last ‘a’ (or the first ‘a’), and we get longest repeated character substring “aaaaaa” with length 6.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> text = “aaaaa”</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> No need to swap, longest repeated character substring is “aaaaa” with length is 5.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= text.length <= 2 * 10<sup>4</sup></code></li>
<li><code>text</code> consist of lowercase English characters only.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxRepOpt1
-