125. Valid Palindrome

125. Valid Palindrome

class Solution {
    public boolean isPalindrome(String s) {

        StringBuilder sIgnoreBuffer = new StringBuilder();
        for (int i = 0; i < s.length(); i++){
            if((s.charAt(i)>='0' && s.charAt(i)<='9')||(s.charAt(i) >= 'a' && s.charAt(i) <= 'z') || (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z'))
                sIgnoreBuffer.append(Character.toLowerCase(s.charAt(i)));
        }
    
        String sIgnore = sIgnoreBuffer.toString();
        int start = 0;
        int end = sIgnore.length() - 1;   
                                
        while(start < end){
            if(sIgnore.charAt(start) == sIgnore.charAt(end)){
                start++;
                end --;
            } else return false;
        }
       return true;
}}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s