Valid Palindrome

基础

但是要掌握 int a = 'A'这种写法,以及

s.trim();
s = s.toUpperCase();

public class Solution {
    public boolean isPalindrome(String s) {
        if(s==null || s.length()<=1) return true;
        s.trim();
        s = s.toUpperCase();
        
        int low = 0, low1 = '0', low2 = 'A';
        int high = s.length()-1, high1 = '9', high2 = 'Z';
        while(low<high){
            if((s.charAt(low)<low1 || s.charAt(low)>high1) &&(s.charAt(low)<low2 || s.charAt(low)>high2)){
                low++;
                continue;
            }
            if((s.charAt(high)<low1 || s.charAt(high)>high1) &&(s.charAt(high)<low2 || s.charAt(high)>high2)){
                high--;
                continue;
            }
            if(s.charAt(low)==s.charAt(high)){
                high--;
                low++;
            }else
                return false;
        }
        return true;
    }
}

 

posted @ 2015-06-10 11:04  世界到处都是小星星  阅读(154)  评论(0编辑  收藏  举报