mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
45 lines
1.1 KiB
HTML
45 lines
1.1 KiB
HTML
<p>如果字符串中的所有字符都相同,那么这个字符串是单字符重复的字符串。</p>
|
||
|
||
<p>给你一个字符串 <code>text</code>,你只能交换其中两个字符一次或者什么都不做,然后得到一些单字符重复的子串。返回其中最长的子串的长度。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>text = "ababa"
|
||
<strong>输出:</strong>3
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>text = "aaabaaa"
|
||
<strong>输出:</strong>6
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>text = "aaabbaaa"
|
||
<strong>输出:</strong>4
|
||
</pre>
|
||
|
||
<p><strong>示例 4:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>text = "aaaaa"
|
||
<strong>输出:</strong>5
|
||
</pre>
|
||
|
||
<p><strong>示例 5:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>text = "abcdef"
|
||
<strong>输出:</strong>1
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= text.length <= 20000</code></li>
|
||
<li><code>text</code> 仅由小写英文字母组成。</li>
|
||
</ul>
|