[LeetCode] 125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama"
is a palindrome."race a car"
is not a palindrome.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
Subscribe to see which companies asked this question
只考慮字母的並驗證 一串字串是不是 回文字串.
class Solution(object):
def isPalindrome(self, s):
s = str(s)
temp = filter(str.isalnum, s.lower()) // 只考慮字母 並全部轉小寫
i = 0
j = len(temp)-1
while( i <= j ): // 從前後 雙pointer 掃
if temp[i] == temp[j] :
i += 1
j -= 1
pass
else:
return False
留言
張貼留言