[虚拟机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.
Function Description Complete the function breakPalindrome in the editor below. The function must return the resulting string or IMPOSSIBLE if one cannot be formed. s: the original string 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。 ? 思路: 代码: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |