马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.
Example 1:
Input: "aba"
Output: True
Example 2:
Input: "abca"
Output: True
Explanation: You could delete the character 'c'.
Note:
The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
class Solution:
def validPalindrome(self, s: str) -> bool:
start = 0
end = len(s) - 1
while start <= end:
if s[start] != s[end]:
first = s[start: end]
second = s[start + 1: end + 1]
return first == first[::-1] or second == second[::-1]
start += 1
end -= 1
return True
|