Java Solution 7ms


  • 0
    B
    public boolean isPalindrome(String s) {
        int end = s.length() - 1;
        char[] arr = s.toCharArray();
        for(int i = 0; i < arr.length; i++) {
            if(!Character.isLetterOrDigit(arr[i]))
                continue;
            while(!Character.isLetterOrDigit(arr[end])) {
                --end;
            }
            if(Character.toLowerCase(arr[i]) == Character.toLowerCase(arr[end])) {
                if(i == end) {
                    break;
                }else{
                    --end;        
                    continue; 
                }
            }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.