Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Input: "A man, a plan, a canal: Panama"
Output: true
Input: "race a car"
Output: false
import java.lang.StringBuilder;
class Solution {
public boolean isPalindrome(String s) {
String connected = s.toLowerCase().replaceAll("[^a-z0-9]", "");
for (int i = 0, j = connected.length() - 1; i < j; i++, j--) {
char c1 = connected.charAt(i);
char c2 = connected.charAt(j);
if (c1 != c2) {
return false;
}
}
return true;
}
}