[Java/C++/Python] Easy and Concise
Check half of the string,\nreplace a non \'a\' character to \'a\'.\n\nIf only one character, return empty string.\nOtherwise repalce the last character to \'b\'
Check half of the string,\nreplace a non `\'a\'` character to `\'a\'`.\n\nIf only one character, return empty string.\nOtherwise repalce the last character to `\'b\'`\n<br>\n\n## **Complexity**\nTime `O(N)`\nSpace `O(N)`\n<br>\n\n**Java**\nFrom @kniffina\n```java\n    public String breakPalindrome(String palindrome) {\n        char[] s = palindrome.toCharArray();\n        int n = s.length;\n\n        for (int i = 0; i < n / 2; i++) {\n            if (s[i] != \'a\') {\n                s[i] = \'a\';\n                return String.valueOf(s);\n            }\n        }\n        s[n - 1] = \'b\'; //if all \'a\'\n        return n < 2 ? "" : String.valueOf(s);\n    }\n```\n**C++**\n```cpp\n    string breakPalindrome(string S) {\n        int n = S.size();\n        for (int i = 0; i < n / 2; ++i) {\n            if (S[i] != \'a\') {\n                S[i] = \'a\';\n                return S;\n            }\n        }\n        S[n - 1] = \'b\';\n        return n < 2 ? "" : S;\n    }\n```\n**Python**\n```py\n    def breakPalindrome(self, S):\n        for i in xrange(len(S) / 2):\n            if S[i] != \'a\':\n                return S[:i] + \'a\' + S[i + 1:]\n        return S[:-1] + \'b\' if S[:-1] else \'\'\n```\n\n
[]