### Three Sum Closest - Leet Code Solution

Problem Statement Given an array nums of n integers and an integer target, find…

September 11, 2020

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

**Example**

```
Input: "A man, a plan, a canal: Panama"
Output: true
Input: "race a car"
Output: false
```

Please note the special conditions:

- Ignore case
- Ignore any non-alphanumeric character

Lets run our simple two pointer system where:

- One pointer will start from left, while other start from extreme right end.
- Lets move left and right pointers untill they are pointing to a non-alphanumeric character
- Compare characters at both left and right position, check must be case-insensitive

```
public static boolean isAlphanumeric(char c) {
return Character.isDigit(c) || Character.isLetter(c);
}
public boolean isPalindrome(String s) {
if (s.length() == 0) return true;
int l = 0;
int r = s.length()-1;
while (l < r) {
while (!isAlphanumeric(s.charAt(l)) && l < r) {
l++;
}
while (!isAlphanumeric(s.charAt(r)) && l < r) {
r--;
}
if (Character.toLowerCase(s.charAt(l)) != Character.toLowerCase(s.charAt(r))) {
return false;
}
l++;
r--;
}
return true;
}
```

Its `O(n)`

Problem Statement Given an array nums of n integers and an integer target, find…

Problem The Leetcode file system keeps a log each time some user performs a…

Problem Statement Implement atoi which converts a string to an integer…

A Binary tree is a data structure which has two children nodes attached to it…

Problem Statement Determine whether an integer is a palindrome. An integer is a…

This is another very useful sorting algorithm based on Heap data structure. Read…

Problem Statement You are given a string text of words that are placed among…

Problem Statement You are given a rows x cols matrix grid. Initially, you are…

Problem Statement Given a string s, return the maximum number of unique…

Problem The Leetcode file system keeps a log each time some user performs a…

Problem Statement Replace all spaces in a string with ‘%20’ (three characters…

Problem Implement an algorithm to determine if a string has all the characters…