Easy and Fast Java Solution (12ms)


  • 0
    P
    class Solution {
        public boolean isPalindrome(String s) {
            int len=s.length();
            int start=0,end=len-1;
            while(start<=end && len>0)
            {
                if(s.charAt(start)==' ' || !Character.isLetterOrDigit(s.charAt(start)))
                    start++;
                else if(s.charAt(end)==' ' || !Character.isLetterOrDigit(s.charAt(end)))
                    end--;
                else if(Character.toString(s.charAt(start)).equalsIgnoreCase(Character.toString(s.charAt(end))))
                {
                    start++;
                    end--;
                }
                else
                    return false;
            }
            return true;
        }
    }
    

Log in to reply
 

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