Master Data Structures & Algorithms For FREE at AlgoMap.io!
@Code_Creator1239 ай бұрын
Great explanation brother , thanks From India 🎉🎉❤
@GregHogg9 ай бұрын
Glad to hear it! 🔥
@vidhansaini92962 ай бұрын
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)
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.
@GregHogg6 ай бұрын
Yes you could, although I think this solution is a lot more intuitive
@praveenchandkakarla4064 ай бұрын
@@GregHogg Exactly it's a clear explanation. Great work, Thanks!! Greg
@KasthuriarachichigePrasanna3 ай бұрын
great bro
@technicallytechnical13 ай бұрын
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Ай бұрын
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Ай бұрын
@@Redaxi thanks but I knew it weeks prior 🫱🏽🫲🏼
@roccococolombo20449 ай бұрын
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]