my simple java solution, beat 96%


  • 0
    L
    public boolean isPalindrome(String s) {
        if(s == null) return false;
        int size = 0;
        char[] array = new char[s.length()];
        char c;
        for(int i = 0; i < s.length(); i++){
            c = s.charAt(i);
            if(c >= 'A' && c <='Z'){
                array[size++] = (char) (c + 32);
            }else if(c >= 'a' && c <= 'z'){
                array[size++] = c;
            }else if(c >= '0' && c <= '9'){
                array[size++] = c;
            }
        }
        if(size == 0) return true;
        int mid = size / 2,end = size - 1;
        for(int i = 0; i < mid; i++){
            if(array[i] != array[end - i]){
                return false;
            }
        }
        return true;
    }

Log in to reply
 

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