-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path680.py
More file actions
24 lines (23 loc) · 683 Bytes
/
Copy path680.py
File metadata and controls
24 lines (23 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
def validPalindrome(self, s: str) -> bool:
def isPalindrome(str: str) -> bool:
i, j = 0, len(str) - 1
while i < j:
if str[i] == str[j]:
i += 1
j -= 1
else:
return False
return True
s = s.lower()
m, n = 0, len(s) - 1
while m < n:
if s[m] == s[n]:
m += 1
n -= 1
else:
if isPalindrome(s[m + 1:n + 1]) or isPalindrome(s[m:n]):
return True
else:
return False
return True