day15笔记
1.题目描述
2.代码构思(debug)
class Solution:
def validPalindrome(self, s: str) -> bool:
if not s:
return
def checkPalindrome(low, high):
i, j = low, high
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
low, high = 0, len(s) - 1
while low < high:
if s[low] == s[high]:
low += 1
high -= 1
else:
return checkPalindrome(low + 1, high) or checkPalindrome(low, high - 1)
return True
class Solution:
def isPalindrome(self, s: str) -> bool:
if not s:
return True
left = 0
right = len(s) - 1
while left < right:
if not s[left].isalpha() and not s[left].isdigit():
left += 1
continue
if not s[right].isalpha() and not s[right].isdigit():
right -= 1
continue
if left < right and s[left].lower() == s[right].lower():
left += 1
right -= 1
else:
return False
return True