File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Python/Interviewbit/Strings Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments