leetcode/125-240524-pass/main.py

25 lines
622 B
Python
Raw Normal View History

2024-05-24 19:37:30 +02:00
def isPalindrome(s: str) -> bool:
tmp = s
tmp = tmp.lower()
def is_char(ch):
if (ch >= 'a' and ch <= 'z') or (ch >= '0' and ch <= '9'):
return True
return False
exp = []
for lt in tmp:
if is_char(lt):
exp.append(lt)
length = len(exp)
for index, ele in enumerate(exp):
if(exp[index] != exp[length - index - 1]):
return False
return True
s = 'A man, a plan a canal: Panama'
print(isPalindrome(s))
s = " "
print(isPalindrome(s))
s = "race a car"
print(isPalindrome(s))
s = "0P"
print(isPalindrome(s))