1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-26 02:00:27 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/单字符重复子串的最大长度 [swap-for-longest-repeated-character-substring].html

45 lines
1.1 KiB
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>如果字符串中的所有字符都相同,那么这个字符串是单字符重复的字符串。</p>
<p>给你一个字符串&nbsp;<code>text</code>,你只能交换其中两个字符一次或者什么都不做,然后得到一些单字符重复的子串。返回其中最长的子串的长度。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>text = &quot;ababa&quot;
<strong>输出:</strong>3
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>text = &quot;aaabaaa&quot;
<strong>输出:</strong>6
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>text = &quot;aaabbaaa&quot;
<strong>输出:</strong>4
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>text = &quot;aaaaa&quot;
<strong>输出:</strong>5
</pre>
<p><strong>示例 5</strong></p>
<pre><strong>输入:</strong>text = &quot;abcdef&quot;
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= text.length &lt;= 20000</code></li>
<li><code>text</code> 仅由小写英文字母组成。</li>
</ul>