【Microsoft面经】OA 2019 | Min Adj Swaps to Make Palindrome Microsoft OA 开发岗

喵贵妃 2020-5-9 1032


Given a string, what is the minimum number of adjacent swaps required to convert a string into a palindrome. If not possible, return -1.

Example 1:

Input: "mamad"

Output: 3

Example 2:

Input: "asflkj"

Output: -1

Example 3:

Input: "aabb"

Output: 2

Example 4:

Input: "ntiin"

Output: 1

Explanation: swap 't' with 'i' => "nitin"

最后于 2020-6-1 被maomoke编辑 ,原因:
最新回复 (0)
返回