passed 11s java code


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

Log in to reply
 

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