680. Valid Palindrome II
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.
------
Intuition
String is valid palindrome if characters at both ends are equal through full string length. Two pointers at left, and right of string can check for exact palindrome.
On the first mismatch, rest of the string, either excluding left, or excluding right character should be exact palindrome.
Time - O(n)
Space - O(1)