1328.cpp (387B)
1 class Solution { 2 public: 3 string breakPalindrome(string palindrome) const { 4 const int n = size(palindrome); 5 if (n == 1) return ""; 6 7 for (int i = 0; i < n / 2; i++) { 8 if (palindrome[i] == 'a') continue; 9 palindrome[i] = 'a'; 10 return palindrome; 11 } 12 13 palindrome[n - 1] = 'b'; 14 return palindrome; 15 } 16 };