> For the complete documentation index, see [llms.txt](https://zedive.gitbook.io/project-l/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zedive.gitbook.io/project-l/part-1/basic_data_structure/array_and_string/two-pointers/lr-pointers/valid-palindrome.md).

# Valid Palindrome

## Question ([LC.125](https://leetcode.com/problems/valid-palindrome/))

> Given a string, verify whether it is a palindrome.

## Example

```
("A man, a plan, a canal: Panama") => true
("Lol") => true
(" ,") => true
```

Only alphanumeric characters count. Not case-sensitive.

## Analysis

L/R pointers. Have a skipping function and checking function that ignores the case.

## Code

```java
public boolean isPalindrome(String text) {
    if (text == null || text.length() <= 1) {
        return true;
    }
    int i = 0, j = text.length() - 1;
    while (i < j) {
        while (i < j && !Character.isLetterOrDigit(text.charAt(i))) {
            i++;
        }
        while (i < j && !Character.isLetterOrDigit(text.charAt(j))) {
            j--;
        }
        if (Character.toLowerCase(text.charAt(i)) != Character.toLowerCase(text.charAt(j))) {
            return false;
        }
        i++;
        j--;
    }
    return true;
}
```
