Class Solution
java.lang.Object
g2101_2200.s2193_minimum_number_of_moves_to_make_palindrome.Solution
2193 - Minimum Number of Moves to Make Palindrome.<p>Hard</p>
<p>You are given a string <code>s</code> consisting only of lowercase English letters.</p>
<p>In one <strong>move</strong> , you can select any two <strong>adjacent</strong> characters of <code>s</code> and swap them.</p>
<p>Return <em>the <strong>minimum number of moves</strong> needed to make</em> <code>s</code> <em>a palindrome</em>.</p>
<p><strong>Note</strong> that the input will be generated such that <code>s</code> can always be converted to a palindrome.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “aabb”</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>We can obtain two palindromes from s, “abba” and “baab”.</p>
<ul>
<li>
<p>We can obtain “abba” from s in 2 moves: “a<strong>ab</strong>b” -> “ab<strong>ab</strong>” -> “abba”.</p>
</li>
<li>
<p>We can obtain “baab” from s in 2 moves: “a<strong>ab</strong>b” -> “<strong>ab</strong>ab” -> “baab”.</p>
</li>
</ul>
<p>Thus, the minimum number of moves needed to make s a palindrome is 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “letelt”</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>One of the palindromes we can obtain from s in 2 moves is “lettel”.</p>
<p>One of the ways we can obtain it is “lete<strong>lt</strong>” -> “let<strong>et</strong>l” -> “lettel”.</p>
<p>Other palindromes such as “tleelt” can also be obtained in 2 moves.</p>
<p>It can be shown that it is not possible to obtain a palindrome in less than 2 moves.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 2000</code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
<li><code>s</code> can be converted to a palindrome using a finite number of moves.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minMovesToMakePalindrome
-