Skip to content

Commit 0118ff8

Browse files
committed
Palindrome String
1 parent 59dabe7 commit 0118ff8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Problem Link: https://www.interviewbit.com/problems/palindrome-string/
3+
4+
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
5+
6+
Example:
7+
"A man, a plan, a canal: Panama" is a palindrome.
8+
"race a car" is not a palindrome.
9+
Return 0 / 1 ( 0 for false, 1 for true ) for this problem
10+
"""
11+
class Solution:
12+
# @param A : string
13+
# @return an integer
14+
def isPalindrome(self, A):
15+
start, end = 0, len(A) - 1
16+
while start < end:
17+
if not A[start].isalnum():
18+
start += 1
19+
elif not A[end].isalnum():
20+
end -= 1
21+
elif A[start].lower() != A[end].lower():
22+
return 0
23+
else:
24+
start += 1
25+
end -= 1
26+
return 1

0 commit comments

Comments
 (0)