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)/两个相同字符之间的最长子字符串 [largest-substring-between-two-equal-characters].html
2022-03-29 12:43:11 +08:00

42 lines
1.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>给你一个字符串 <code>s</code>,请你返回 <strong>两个相同字符之间的最长子字符串的长度</strong> <em></em>计算长度时不含这两个字符。如果不存在这样的子字符串,返回 <code>-1</code></p>
<p><strong>子字符串</strong> 是字符串中的一个连续字符序列。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s = "aa"
<strong>输出:</strong>0
<strong>解释:</strong>最优的子字符串是两个 'a' 之间的空子字符串。</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s = "abca"
<strong>输出:</strong>2
<strong>解释:</strong>最优的子字符串是 "bc" 。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>s = "cbzxy"
<strong>输出:</strong>-1
<strong>解释:</strong>s 中不存在出现出现两次的字符,所以返回 -1 。
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>s = "cabbac"
<strong>输出:</strong>4
<strong>解释:</strong>最优的子字符串是 "abba" ,其他的非最优解包括 "bb" 和 "" 。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 300</code></li>
<li><code>s</code> 只含小写英文字母</li>
</ul>