@@AM-wx9zl Yes, it does -- going through 'aba' once doesn't work, b/c 'aaa' is a palindrome, so if you make the last letter 'b', you get 'abb', which is the correct answer ...
@@icaryslittle6370 you've already changed it to 'aaa' at that point, swapping the last letter to get 'aab' is the wrong answer. I may have misunderstood your original comment, do you have a code example? I couldn't get it to work but I'm not great at leetcode
Not that good *YET* ... Keep practicing, brother ... class Solution(object): def breakPalindrome(self, palindrome): if len(palindrome) == 1: return '' p = list(palindrome) for x in range(len(p)/2): temp = p[x] p[x] ='a' if p != p[::-1]: return ''.join(p) p[x] = temp p[-1] = 'b' if p != p[::-1]: return ''.join(p) return ''
No need to go through it twice ... If the 'a' doesn't work and the string is more than one character, just make 'b' the last letter ...
Lol you are correct! Nice catch
Doesn't work for "aba"
@@AM-wx9zl Yes, it does -- going through 'aba' once doesn't work, b/c 'aaa' is a palindrome, so if you make the last letter 'b', you get 'abb', which is the correct answer ...
@@icaryslittle6370 you've already changed it to 'aaa' at that point, swapping the last letter to get 'aab' is the wrong answer. I may have misunderstood your original comment, do you have a code example? I couldn't get it to work but I'm not great at leetcode
Not that good *YET* ... Keep practicing, brother ...
class Solution(object):
def breakPalindrome(self, palindrome):
if len(palindrome) == 1:
return ''
p = list(palindrome)
for x in range(len(p)/2):
temp = p[x]
p[x] ='a'
if p != p[::-1]:
return ''.join(p)
p[x] = temp
p[-1] = 'b'
if p != p[::-1]:
return ''.join(p)
return ''
Op .... Means orey puka ✅✅💥💥