Valid Palindrome - Leetcode 125 - 2 Pointers (Python)

  Рет қаралды 6,562

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 13
@GregHogg
@GregHogg 3 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@Code_Creator123
@Code_Creator123 9 ай бұрын
Great explanation brother , thanks From India 🎉🎉❤
@GregHogg
@GregHogg 9 ай бұрын
Glad to hear it! 🔥
@vidhansaini9296
@vidhansaini9296 2 ай бұрын
s = ''.join(c for c in s if c.isalnum()) s = s.lower() if s == s[::-1]: return True return False can solve it like this as well without using pointer but space complexity is now o(n)
@mikekertser5384
@mikekertser5384 9 ай бұрын
def isPalindrome(word): return word.lower() == ''.join(reversed(word.lower()))
@manishluckyreddy6710
@manishluckyreddy6710 7 ай бұрын
Can we solve the same problem using recursion? if yes, how can we do it. I'm trying to do so but I'm not getting it. Thanks in advance.
@GregHogg
@GregHogg 6 ай бұрын
Yes you could, although I think this solution is a lot more intuitive
@praveenchandkakarla406
@praveenchandkakarla406 4 ай бұрын
@@GregHogg Exactly it's a clear explanation. Great work, Thanks!! Greg
@KasthuriarachichigePrasanna
@KasthuriarachichigePrasanna 3 ай бұрын
great bro
@technicallytechnical1
@technicallytechnical1 3 ай бұрын
explain this bro : class Solution(object): def isPalindrome(self, s): return re.sub(r'[^A-Za-z0-9]', '', s.lower())==re.sub(r'[^A-Za-z0-9]', '', s.lower()[::-1])
@Redaxi
@Redaxi Ай бұрын
re is the regex module, re.sub takes the regex pattern as a parameter which is "[^A-Za-z0-9]" here. This re.sub removes what is not in A-Z and a-z and 0-9. So basically it removes all that is non alphanumeric. then does s.lower, to make it all lowercase, on the right side it does the same thing but with [::-1] which is pythons slice op it takes start end step, start and end are empty so it takes the whole string and step is -1 so it goes in reverse, resulting in the reversed string, and if the reversed and normal modified strings are same then it returns True, i.e. string is a valid palindrome
@technicallytechnical1
@technicallytechnical1 Ай бұрын
@@Redaxi thanks but I knew it weeks prior 🫱🏽‍🫲🏼
@roccococolombo2044
@roccococolombo2044 9 ай бұрын
Also: def isPalindrome(s: str): # Clean s str_cleaned = ''.join(char.lower() for char in s if char.isalpha()) # Compare forward to backward return str_cleaned == str_cleaned[::-1]
Valid Palindrome - Leetcode 125 - Python
14:58
NeetCode
Рет қаралды 273 М.
When u fight over the armrest
00:41
Adam W
Рет қаралды 11 МЛН
小丑揭穿坏人的阴谋 #小丑 #天使 #shorts
00:35
好人小丑
Рет қаралды 37 МЛН
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 17 МЛН
Wait… Maxim, did you just eat 8 BURGERS?!🍔😳| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 8 МЛН
Diameter of Binary Tree - Leetcode 543 - Trees (Python)
11:16
3Sum - Leetcode 15 - 2 Pointers (Python)
9:42
Greg Hogg
Рет қаралды 12 М.
Rabin Karp - Shortest Palindrome - Leetcode 214
22:07
NeetCodeIO
Рет қаралды 17 М.
Valid Parentheses - Leetcode 20 - Stacks (Python)
8:55
Greg Hogg
Рет қаралды 8 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 322 М.
Valid Palindrome II - Leetcode 680 - Python
7:46
NeetCode
Рет қаралды 47 М.
Top K Frequent Elements - Leetcode 347 - Heaps (Python)
14:08
Greg Hogg
Рет қаралды 10 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 668 М.
When u fight over the armrest
00:41
Adam W
Рет қаралды 11 МЛН