Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 657 Bytes

File metadata and controls

23 lines (17 loc) · 657 Bytes

Break a Palindrome

Problem can be found in here!

def breakPalindrome(palindrome: str) -> str:
    if len(palindrome) == 1:
        return ""

    string = list(palindrome)
    for index in range(len(string) // 2):
        if string[index] != "a":
            string[index] = "a"
            break
    else:
        string[-1] = "b"

    return "".join(string)

Time Complexity: O(n), Space Complexity: O(n)