Leetcode - Break a Palindrome (Python)

  Рет қаралды 5,702

Timothy H Chang

Timothy H Chang

Күн бұрын

Пікірлер: 7
@icaryslittle6370
@icaryslittle6370 3 жыл бұрын
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 ...
@timc3406
@timc3406 3 жыл бұрын
Lol you are correct! Nice catch
@AM-wx9zl
@AM-wx9zl 2 жыл бұрын
Doesn't work for "aba"
@icaryslittle6370
@icaryslittle6370 2 жыл бұрын
@@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 ...
@AM-wx9zl
@AM-wx9zl 2 жыл бұрын
@@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
@icaryslittle6370
@icaryslittle6370 2 жыл бұрын
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 ''
@SeethaYt
@SeethaYt 2 жыл бұрын
Op .... Means orey puka ✅✅💥💥
Rabin Karp - Shortest Palindrome - Leetcode 214
22:07
NeetCodeIO
Рет қаралды 17 М.
Palindrome Partition Dynamic Programming
11:46
Tushar Roy - Coding Made Simple
Рет қаралды 105 М.
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 248 МЛН
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 19 МЛН
Smart Sigma Kid #funny #sigma
00:33
CRAZY GREAPA
Рет қаралды 27 МЛН
Python Leetcode Coding - Stacks (1)
18:11
Timothy H Chang
Рет қаралды 823
So You've Been Rejected from FAANG
5:56
Timothy H Chang
Рет қаралды 9 М.
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 452 М.
Leetcode problem Break a Palindrome
8:59
Errichto Algorithms
Рет қаралды 38 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 28 МЛН
Longest Palindrome - Leetcode 409 - Python
12:20
NeetCodeIO
Рет қаралды 15 М.
LeetCode 1328 - Break a Palindrome
13:54
Light Of Truth
Рет қаралды 1,3 М.
2 Years of C++ Programming
8:20
Zyger
Рет қаралды 8 М.
Subarrays with K Different Integers - Leetcode 992 - Python
17:31
Valid Palindrome - Leetcode 125 - Python
14:58
NeetCode
Рет қаралды 280 М.
How many people are in the changing room? #devil #lilith #funny #shorts
00:39