-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathisPalindrome.py
More file actions
25 lines (17 loc) · 786 Bytes
/
isPalindrome.py
File metadata and controls
25 lines (17 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 125. Palindrome
# 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.
class Solution:
def isPalindrome(self, s: str) -> bool:
alpha = ''.join(char for char in s.lower() if char.isalnum())
start = 0
end = len(alpha)-1
if s == ' ':
return True
while (start < end):
if alpha[start] != alpha[end]:
return False
else:
start += 1
end -= 1
return True