[Leetcode]-- Valid Palindrome

public class Solution {
    public boolean isPalindrome(String s) {
        if(s  == null || s.length() <2 ){
            return true;
        }
        
        String mystring = s.replaceAll("[^A-Za-z0-9]", "");
        mystring = mystring.toLowerCase();
        
        // 只需遍历前一半就可以了
        for(int i = 0 ; i< mystring.length()/2; i++){
            if(mystring.charAt(i) != mystring.charAt(mystring.length() - 1 - i)){
                return false;
            }
        }
        return true;
        
    }
}

 

posted @ 2014-01-26 07:18  Razer.Lu  阅读(93)  评论(0编辑  收藏  举报