mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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 <= s.length <= 300</code></li>
 | 
						||
	<li><code>s</code> 只含小写英文字母</li>
 | 
						||
</ul>
 |