不想写第二遍的刷题笔记

世界级打野都是rush大龙的

Valid Palindrome

LeetCode 125

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.

Example 1:

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

Example 2:

Input: "race a car"
Output: false

Solution

class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
new_s = ""
for i in s:
if i.isalpha() or i.isdigit():
new_s += i
new_s = new_s.lower()
print(new_s)
if new_s[::-1] == new_s:
return True
else:
return False