码迷,mamicode.com
首页 > 其他好文 > 详细

Valid Palindrome

时间:2015-06-10 11:56:06      阅读:101      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!