首页 > 其他 > 详细

Valid Palindrome

时间:2015-06-10 11:53:34      阅读:123      评论:0      收藏:0      [点我收藏+]

基础

但是要掌握 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;
    }
}

 

Valid Palindrome

原文:http://www.cnblogs.com/jiajiaxingxing/p/4565475.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!