My 12ms Java Solution


  • 0
    L
    public class Solution {
        public boolean isPalindrome(String s) {
            char[] c = s.toLowerCase().toCharArray();
            int i = 0;
            int j = c.length-1;
            String alphanumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            
            
            while (i<j){
                if (alphanumeric.indexOf(c[i]) == -1){
                    i++;
                }
                else if (alphanumeric.indexOf(c[j]) == -1){
                    j--;
                }
                else {                
                    if (c[i] == c[j]){
                        i++;
                        j--;
                    }   
                    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.