My accepted java solution using two index


  • 0
    E
    public boolean isPalindrome(String s) {
        if(s== null || s.length()==1) return true;
        int start = 0, end = 0, len =s.length() ;
        while (start + end < len-1){
            while(!Character.isLetter(s.charAt(start))&& !Character.isDigit(s.charAt(start))&& start + end < len -1 ) ++ start;
            while(!Character.isLetter(s.charAt(len-1-end)) && !Character.isDigit(s.charAt(len-1-end)) && start + end < len -1 ) ++ end;
            if(Character.toLowerCase(s.charAt(start)) != Character.toLowerCase(s.charAt(len-1-end))) return false;
            ++ start;
            ++ end;
        }
        return true;
    }

Log in to reply
 

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