1328. Break a Palindrome Medium

@problem@discussion
#String#Greedy



1/**
2 * [1328] Break a Palindrome
3 *
4 * Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically smallest one possible.
5 * Return the resulting string. If there is no way to replace a character to make it not a palindrome, return an empty string.
6 * A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, a has a character strictly smaller than the corresponding character in b. For example, "abcc" is lexicographically smaller than "abcd" because the first position they differ is at the fourth character, and 'c' is smaller than 'd'.
7 *  
8 * Example 1:
9 * 
10 * Input: palindrome = "abccba"
11 * Output: "aaccba"
12 * Explanation: There are many ways to make "abccba" not a palindrome, such as "<u>z</u>bccba", "a<u>a</u>ccba", and "ab<u>a</u>cba".
13 * Of all the ways, "aaccba" is the lexicographically smallest.
14 * 
15 * Example 2:
16 * 
17 * Input: palindrome = "a"
18 * Output: ""
19 * Explanation: There is no way to replace a single character to make "a" not a palindrome, so return an empty string.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= palindrome.length <= 1000
25 * 	palindrome consists of only lowercase English letters.
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/break-a-palindrome/
31// discuss: https://leetcode.com/problems/break-a-palindrome/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn break_palindrome(palindrome: String) -> String {
37        String::new()
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_1328() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.