1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/分割回文串 III [palindrome-partitioning-iii].html
2022-03-29 12:43:11 +08:00

41 lines
1.4 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>s</code>,和一个整数&nbsp;<code>k</code></p>
<p>请你按下面的要求分割字符串:</p>
<ul>
<li>首先,你可以将&nbsp;<code>s</code>&nbsp;中的部分字符修改为其他的小写英文字母。</li>
<li>接着,你需要把&nbsp;<code>s</code>&nbsp;分割成&nbsp;<code>k</code>&nbsp;个非空且不相交的子串,并且每个子串都是回文串。</li>
</ul>
<p>请返回以这种方式分割字符串所需修改的最少字符数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s = &quot;abc&quot;, k = 2
<strong>输出:</strong>1
<strong>解释:</strong>你可以把字符串分割成 &quot;ab&quot;&quot;c&quot;,并修改 &quot;ab&quot; 中的 1 个字符,将它变成回文串。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s = &quot;aabbc&quot;, k = 3
<strong>输出:</strong>0
<strong>解释:</strong>你可以把字符串分割成 &quot;aa&quot;&quot;bb&quot;&quot;c&quot;,它们都是回文串。</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>s = &quot;leetcode&quot;, k = 8
<strong>输出:</strong>0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= k &lt;= s.length &lt;= 100</code></li>
<li><code>s</code>&nbsp;中只含有小写英文字母。</li>
</ul>