五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode Lexicographically Smallest Palindrome

2023-05-21 12:29 作者:您是打尖兒還是住店呢  | 我要投稿


You are given a string?s?consisting of?lowercase English letters, and you are allowed to perform operations on it. In one operation, you can?replace?a character in?s?with another lowercase English letter.

Your task is to make?s?a?palindrome?with the?minimum?number?of operations?possible. If there are?multiple palindromes?that can be?made using the?minimum?number of operations,?make the?lexicographically smallest?one.

A string?a?is lexicographically smaller than a string?b?(of the same length) if in the first position where?a?and?b?differ, string?a?has a letter that appears earlier in the alphabet than the corresponding letter in?b.

Return?the resulting palindrome string.

?

Example 1:

Input: s = "egcfe"

Output: "efcfe"

Explanation: The minimum number of operations to make "egcfe" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "efcfe", by changing 'g'.

Example 2:

Input: s = "abcd"

Output: "abba"

Explanation: The minimum number of operations to make "abcd" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is "abba".

Example 3:

Input: s = "seven"

Output: "neven"

Explanation: The minimum number of operations to make "seven" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "neven".

?就是將文字變成回文字符串,但是是有條件的,就是字典序最小,簡單的一次遍歷,每次判斷即可,但是我把問題復雜化了,所以一直沒過。。。

Constraints:

  • 1 <= s.length <= 1000

  • s?consists of only lowercase English letters.


Runtime:?10 ms, faster than?83.33%?of?Java?online submissions for?Lexicographically Smallest Palindrome.

Memory Usage:?44.6 MB, less than?16.67%?of?Java?online submissions for?Lexicographically Smallest Palindrome.



LeetCode Lexicographically Smallest Palindrome的評論 (共 條)

分享到微博請遵守國家法律
洪泽县| 乐安县| 鄂州市| 怀集县| 乳山市| 青海省| 延庆县| 喀什市| 探索| 任丘市| 海原县| 布尔津县| 游戏| 尚义县| 三河市| 呼和浩特市| 平度市| 罗城| 延川县| 深州市| 连南| 民乐县| 定西市| 怀柔区| 平顺县| 河东区| 张掖市| 平塘县| 株洲市| 望城县| 峨边| 正宁县| 讷河市| 望江县| 乡宁县| 永昌县| 渭南市| 西吉县| 隆回县| 大厂| 拉萨市|