Simple java solution


  • 0
    A
    public class Solution {
        public boolean isPalindrome(String s) {
            int length = s.length();
            int i = 0;
            int j = length - 1;
            while(i < j){
                while(i < length && !Character.isLetterOrDigit(s.charAt(i))){
                    i++;
                }
                while(j >= 0 && !Character.isLetterOrDigit(s.charAt(j))){
                    j--;
                }
                if(i < length && j >= 0 && 
                    Character.toLowerCase(s.charAt(i)) != Character.toLowerCase(s.charAt(j))){
                    return false;
                }
                i++;
                j--;
            }
            return true;
        }
    }

Log in to reply
 

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