<p>Given a string <code>s</code>, return <code>true</code> <em>if the </em><code>s</code><em> can be palindrome after deleting <strong>at most one</strong> character from it</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aba&quot;
<strong>Output:</strong> true
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abca&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> You could delete the character &#39;c&#39;.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abc&quot;
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>s</code> consists of lowercase English letters.</li>
</ul>

class Solution(object):
    def validPalindrome(self, s):
        if s == s[::-1]:
            return True

        left, right = 0, len(s) - 1
        while left <= right:
            if s[left] != s[right]:
                substring1 = s[left:right]
                substring2 = s[left + 1:right + 1]
                return substring1 == substring1[::-1] or substring2 == substring2[::-1]
            left += 1
            right -= 1

        return True



# """
# Time: O(n)
# Space: O(n)

# class Solution(object):
#     def validPalindrome(self, s):
#         if s == s[::-1]:
#             return True

#         left, right = 0, len(s) - 1
#         while left <= right:
#             if s[left] != s[right]: # in this case, either left or right be the deleted one.
#                 # either delete left or delte right one, then....
#                 # we only care about the sub string that hasn't been scan yet.
#                 one, two = s[left : right], s[left + 1 : right + 1]  # remove the right or left to see the reset can be parlindrome or not
#                 return one == one[::-1] or two == two[::-1]   # only consider the middle part
#             left, right = left + 1, right - 1

#         return True
# """

"""
# TLE
class Solution:
    def validPalindrome(self, s: str) -> bool:
        if s[::-1] == s: 
            return True
        
        s = list(s)
        for i in range(len(s)): 
            c = s[i]
            del s[i]
            if s == s[::-1]: 
                return True
            else: 
                s.insert(i, c)
            
        return False
"""

16900