Skip to content

Commit aa1fa71

Browse files
committedDec 12, 2020
feat: valid-palindrome
1 parent 37ca820 commit aa1fa71

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎str.valid-palindrome.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
"""
3+
125. 验证回文串
4+
https://leetcode-cn.com/problems/valid-palindrome/
5+
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
6+
说明:本题中,我们将空字符串定义为有效的回文串。
7+
"""
8+
def isPalindrome(self, s: str) -> bool:
9+
# isalnum: 是否是数字和字母构成
10+
res = ''.join(ch.lower() for ch in s if ch.isalnum())
11+
return res == res[::-1]
12+
13+
14+
so = Solution()
15+
print(so.isPalindrome('A man, a plan, a canal: Panama'))

0 commit comments

Comments
 (0)
Please sign in to comment.