Very concise Java solution


  • 0
    public class Solution {
        public boolean isPalindrome(String s) {
            if(s==null || s.length()==0) return true;
            int l=0, r=s.length()-1;
            while(l<r){
                if(!Character.isLetterOrDigit(s.charAt(l))){
                    ++l;
                }else if(!Character.isLetterOrDigit(s.charAt(r))){
                    --r;
                }else if(Character.toLowerCase(s.charAt(l))!=Character.toLowerCase(s.charAt(r))){
                    return false;    
                }else{
                    ++l;
                    --r;
                }
            }
            return true;
        }
    }
    
    

Log in to reply
 

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