Skip to content

Commit 437fd89

Browse files
committed
125.Valid Palindrome.md
1 parent 69c7da0 commit 437fd89

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

String/Easy/125.Valid Palindrome.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# 题目
2+
3+
给定一个字符串,判断这个字符串是不是回文。不考虑标点符合和空格以及大小写。
4+
5+
**举例:**
6+
7+
- "A man, a plan, a canal: Panama" 是回文
8+
- "race a car" 不是回文
9+
10+
**Note:**
11+
12+
- 对于空字符串,默认为回文。
13+
-
14+
15+
----------
16+
17+
# 思路
18+
19+
很简单,使用正则表达式匹配所有字母,并将其转换为小写字母。然后收尾比对,不一样就返回False。
20+
21+
22+
----------
23+
24+
# 代码
25+
26+
```python
27+
class Solution(object):
28+
def isPalindrome(self, s):
29+
"""
30+
:type s: str
31+
:rtype: bool
32+
"""
33+
s = re.findall('\w{1}', s.lower())
34+
s_len = int(len(s) / 2)
35+
for i in range(s_len):
36+
if s[i] != s[-(i+1)]:
37+
return False
38+
return True
39+
```
40+

0 commit comments

Comments
 (0)