1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/找到最长的半重复子字符串 [find-the-longest-semi-repetitive-substring].html

53 lines
2.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个下标从 <strong>0</strong>&nbsp;开始的字符串&nbsp;<code>s</code>&nbsp;,这个字符串只包含&nbsp;<code>0</code>&nbsp;&nbsp;<code>9</code>&nbsp;的数字字符。</p>
<p>如果一个字符串&nbsp;<code>t</code>&nbsp;中至多有一对相邻字符是相等的,那么称这个字符串 <code>t</code><strong>半重复的</strong>&nbsp;。例如,<code>"0010"</code>&nbsp;<code>"002020"</code>&nbsp;<code>"0123"</code>&nbsp;<code>"2002"</code>&nbsp;<code>"54944"</code>&nbsp;是半重复字符串,而 <code>"00101022"</code>&nbsp;(相邻的相同数字对是 00 和 22<code>"1101234883"</code>&nbsp;(相邻的相同数字对是 11 和 88不是半重复字符串。</p>
<p>请你返回 <code>s</code>&nbsp;中最长 <strong>半重复</strong>&nbsp;<span data-keyword="substring-nonempty">子字符串</span> 的长度。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "52233"</span></p>
<p><strong>输出:</strong><span class="example-io">4</span></p>
<p><strong>解释:</strong></p>
<p>最长的半重复子字符串是 "5223"。整个字符串 "52233" 有两个相邻的相同数字对 22 和 33但最多只能选取一个。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "5494"</span></p>
<p><strong>输出:</strong><span class="example-io">4</span></p>
<p><strong>解释:</strong></p>
<p><code>s</code>&nbsp;是一个半重复字符串。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "1111111"</span></p>
<p><strong>输出:</strong><span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p>最长的半重复子字符串是 "11"。子字符串 "111" 有两个相邻的相同数字对,但最多允许选取一个。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 50</code></li>
<li><code>'0' &lt;= s[i] &lt;= '9'</code></li>
</ul>