mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
39 lines
1.2 KiB
HTML
39 lines
1.2 KiB
HTML
<p>Given a string <code>s</code>. In one step you can insert any character at any index of the string.</p>
|
|
|
|
<p>Return <em>the minimum number of steps</em> to make <code>s</code> palindrome.</p>
|
|
|
|
<p>A <b>Palindrome String</b> is one that reads the same backward as well as forward.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "zzazz"
|
|
<strong>Output:</strong> 0
|
|
<strong>Explanation:</strong> The string "zzazz" is already palindrome we do not need any insertions.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "mbadm"
|
|
<strong>Output:</strong> 2
|
|
<strong>Explanation:</strong> String can be "mbdadbm" or "mdbabdm".
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "leetcode"
|
|
<strong>Output:</strong> 5
|
|
<strong>Explanation:</strong> Inserting 5 characters the string becomes "leetcodocteel".
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= s.length <= 500</code></li>
|
|
<li><code>s</code> consists of lowercase English letters.</li>
|
|
</ul>
|