[LC] 125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.< /p>

Example 1:

Input: "A man, a plan, a canal: Panama"

Output: true

Example 2:

Input: "race a car"

Output: false

class Solution(object):

def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
if s is '':
return True
import string
valid
= set(string.ascii_letters + string.digits)
s_cp
= s[:].lower()
left, right
= 0, len(s)-1
while left <= right:
if s_cp[left] not in valid:
left
+= 1
elif s_cp[right] not in valid:
right
-= 1
elif s_cp[left] != s_cp[right]:
return False
else:
left
+= 1
right
-= 1
return True

class Solution(object):

def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
if s is '':
return True
import string
valid
= set(string.ascii_letters + string.digits)
s_cp
= s[:].lower()
left, right
= 0, len(s)-1
while left <= right:
if s_cp[left] not in valid:
left
+= 1
elif s_cp[right] not in valid:
right
-= 1
elif s_cp[left] != s_cp[right]:
return False
else:
left
+= 1
right
-= 1
return True

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3983 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.