mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个字符串数组 <code>words</code> 。<code>words</code> 中每个元素都是一个包含 <strong>两个</strong> 小写英文字母的单词。</p>
 | 
						||
 | 
						||
<p>请你从 <code>words</code> 中选择一些元素并按 <b>任意顺序</b> 连接它们,并得到一个 <strong>尽可能长的回文串</strong> 。每个元素 <strong>至多</strong> 只能使用一次。</p>
 | 
						||
 | 
						||
<p>请你返回你能得到的最长回文串的 <strong>长度</strong> 。如果没办法得到任何一个回文串,请你返回 <code>0</code> 。</p>
 | 
						||
 | 
						||
<p><strong>回文串</strong> 指的是从前往后和从后往前读一样的字符串。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre><b>输入:</b>words = ["lc","cl","gg"]
 | 
						||
<b>输出:</b>6
 | 
						||
<b>解释:</b>一个最长的回文串为 "lc" + "gg" + "cl" = "lcggcl" ,长度为 6 。
 | 
						||
"clgglc" 是另一个可以得到的最长回文串。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre><b>输入:</b>words = ["ab","ty","yt","lc","cl","ab"]
 | 
						||
<b>输出:</b>8
 | 
						||
<strong>解释:</strong>最长回文串是 "ty" + "lc" + "cl" + "yt" = "tylcclyt" ,长度为 8 。
 | 
						||
"lcyttycl" 是另一个可以得到的最长回文串。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre><b>输入:</b>words = ["cc","ll","xx"]
 | 
						||
<b>输出:</b>2
 | 
						||
<b>解释:</b>最长回文串是 "cc" ,长度为 2 。
 | 
						||
"ll" 是另一个可以得到的最长回文串。"xx" 也是。</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= words.length <= 10<sup>5</sup></code></li>
 | 
						||
	<li><code>words[i].length == 2</code></li>
 | 
						||
	<li><code>words[i]</code> 仅包含小写英文字母。</li>
 | 
						||
</ul>
 |