Valid Palindrome II - Problem
Given a string s, return true if the string can be a palindrome after deleting at most one character from it.
A palindrome reads the same forward and backward. For example, "racecar" and "level" are palindromes.
Your task is to determine if removing zero or one character can make the string a palindrome.
Input & Output
Example 1 — Can Make Palindrome
$
Input:
s = "aba"
›
Output:
true
💡 Note:
"aba" is already a palindrome, so we return true without deleting any character
Example 2 — Need One Deletion
$
Input:
s = "abca"
›
Output:
true
💡 Note:
We can delete 'c' to get "aba" or delete 'b' to get "aca", both are palindromes
Example 3 — Cannot Make Palindrome
$
Input:
s = "abc"
›
Output:
false
💡 Note:
No matter which character we delete, we cannot make it a palindrome with just one deletion
Constraints
- 1 ≤ s.length ≤ 105
- s consists of lowercase English letters only
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code