My java solution


  • 0
    R
    public class Solution {
        public boolean isPalindrome(String s) {
            if(s.length()==0)
                return true;
            int low=0;
            int high=s.length()-1;
            while(low<=high){
                while(low<=high&&(!valid(s.charAt(low))))
                    low++;
                while(high>=low&&(!valid(s.charAt(high))))
                    high--;
                if(low>=high)
                    return true;
                if(change(s.charAt(low))!=change(s.charAt(high)))
                    return false;
                low++;
                high--;
                }
            return true;    
            
            
        }
        static boolean valid(char c){
            if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>='0'&&c<='9'))
                return true;
            else
                return false;
        }
        static char change(char c){
            if(c>='a'&&c<='z'){
                char temp=(char)(c-('a'-'A'));
                return temp;
            }
            return c;    
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.