Palindrome String

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

Example:

"A man, a plan, a canal: Panama" is a palindrome.

"race a car" is not a palindrome.

Return 0 / 1 ( 0 for false, 1 for true ) for this problem

public class Solution {
    public int isPalindrome(String A) {
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < A.length(); i++) {
            if ((A.charAt(i) >= 'a' && A.charAt(i) <= 'z') || (A.charAt(i) >= 'A' && A.charAt(i) <= 'Z')
                    || (A.charAt(i) >= '0' && A.charAt(i) <= '9'))
                s.append(A.charAt(i));
        }
        String str = s.toString().toLowerCase();
        int i = 0;
        int j = str.length() - 1;
        while (i < j) {
            if (str.charAt(i) == str.charAt(j)) {
                i++;
                j--;
                continue;
            } else
                return 0;
        }
        return 1;
    }
}

Last updated