A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
\
Mysolution:
class Solution:
def isPalindrome(self, s: str) -> bool:
left, right = 0, len(s) - 1
while left < right:
l, r = str.lower(s[left]),str.lower(s[right])
if not (ord("a") <= ord(l) <= ord("z") or ord("0") <= ord(l) <= ord("9")):
left += 1
elif not (ord("a") <= ord(r) <= ord("z") or ord("0") <= ord(r) <= ord("9")):
right -= 1
elif l == r:
left += 1
right -= 1
else:
return False
return True
Problem:
class Solution:
def isPalindrome(self, s: str) -> bool:
l, r = 0, len(s) - 1
while l < r:
while l < r and not self.isAlphanumeric(s[l]):
l += 1
while r > l and not self.isAlphanumeric(s[r]):
r -= 1
if str.lower(s[l]) != str.lower(s[r]):
return False
l += 1
r -= 1
return True
def isAlphanumeric(self, c: chr) -> bool:
return (ord("a") < ord(c) < ord("z") or
ord("A") < ord(c) < ord("Z") or
ord("0") < ord(c) < ord("9"))
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).
\
Mysolution: