[虚拟机OA]Break a Palindrome 破坏回文串

Posted liuliu5151

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[虚拟机OA]Break a Palindrome 破坏回文串相关的知识,希望对你有一定的参考价值。

In this challenge, you will be given a palindrome which you must modify if possible. Change exactly one character of the string to another character in the range ascii[a-z] so that the string meets the following two conditions:

• The new string is not a palindrome

• The new string is lower lexicographically (alphabetically) than the initial string.

• The new string is the lowest value string lexicographically that can be created from the original palindrome after making only one change.


If it not possible to create a string meeting the criteria, return the string IMPOSSIBLE.

Function Description

Complete the function breakPalindrome in the editor below. The function must return the resulting string or IMPOSSIBLE if one cannot be formed.
breakPalindrome has the following parameter(s):

s: the original string


Sample Case  
Sample Input For Custom Testing

bab

Sample Output 

aab

Explanation The string aab is the smallest string which satisfies all the given conditions.

 

题意:

给定?一个palindrome。要改变?一个char,使得新的string不不是palindrome。?而且要是lexicocographically最?小的,不不然就返回"IMPOSSIBLE"。

把左半边不不是a的改成a就?行行了了。举例例:输?aba。算法算出aaa但仍是回?文字串串,所以输出IMPOSSIBLE。 输?入abba,输出aaba。

 

思路:

代码:

 

以上是关于[虚拟机OA]Break a Palindrome 破坏回文串的主要内容,如果未能解决你的问题,请参考以下文章

leetcode1328. Break a Palindrome

[虚拟机OA]Climb the hill 爬山

[虚拟机OA]Team Formation 2 团队构成

[虚拟机OA]Fun with Anagrams 玩转同构词

[虚拟机OA]Build the Subsequences 生成子序列

[虚拟机OA]Group Anagram 变位词归类