> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/01-31-2022-680.md).

# 01/31/2022 680

use two pointers left from the start of the string and right from the end of the string. Compare them iteratively. If they do not match, then compare left +1 with right or left with right -1.

Time O(n)

Space O(1)

```
public boolean validPalindrome(String s) {
 int left = 0, right = s.length() - 1;
    while (left < right) {
        if (s.charAt(left) != s.charAt(right)) {
            return isPalindrome(s, left + 1, right) || isPalindrome(s, left, right - 1);
        }
        left++;
        right--;
    }

    return true;
}

/* Check is s[i...j] is palindrome. */
private boolean isPalindrome(String s, int i, int j) {
    
    while (i < j) {
        if (s.charAt(i) != s.charAt(j)) {
            return false;
        }
        i++;
        j--;
    }
    
    return true;
}
```
