Short Accepted Java Solution


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

Log in to reply
 

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