Check whether a string can become a palindrome after deleting at most one character.
Given a string s, determine whether it can be converted into a palindrome by removing at most one character.
A palindrome reads the same forward and backward. You may choose to delete zero characters as well, which means an already-palindromic string should return true.
Return true if the string can be made into a palindrome after at most one deletion, otherwise return false.
Input Format
- A single string
s. - The string contains lowercase English letters in the standard LeetCode formulation.
Output Format
- Return
trueifscan be a palindrome after deleting at most one character. - Otherwise return
false.
Constraints
scontains lowercase English letters.- You may delete at most one character.
Example 1
Input
s = "aba"
Output
true
Explanation
The string is already a palindrome, so no deletion is needed.
Example 2
Input
s = "abca"
Output
true
Explanation
Deleting either b or c makes the string a palindrome ("aca" or "aba").
Show 1 more example
Example 3
Input
s = "abc"
Output
false
Explanation
No single deletion can turn it into a palindrome.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.