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)/连接两字母单词得到的最长回文串 [longest-palindrome-by-concatenating-two-letter-words].html
2022-03-29 12:43:11 +08:00

43 lines
1.7 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>给你一个字符串数组&nbsp;<code>words</code>&nbsp;<code>words</code>&nbsp;中每个元素都是一个包含 <strong>两个</strong>&nbsp;小写英文字母的单词。</p>
<p>请你从 <code>words</code>&nbsp;中选择一些元素并按 <b>任意顺序</b>&nbsp;连接它们,并得到一个 <strong>尽可能长的回文串</strong>&nbsp;。每个元素 <strong>至多</strong>&nbsp;只能使用一次。</p>
<p>请你返回你能得到的最长回文串的 <strong>长度</strong>&nbsp;。如果没办法得到任何一个回文串,请你返回 <code>0</code>&nbsp;</p>
<p><strong>回文串</strong>&nbsp;指的是从前往后和从后往前读一样的字符串。</p>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 10<sup>5</sup></code></li>
<li><code>words[i].length == 2</code></li>
<li><code>words[i]</code>&nbsp;仅包含小写英文字母。</li>
</ul>