首页 > 其他 > 详细

[Leetcode]-- Valid Palindrome

时间:2014-01-26 08:47:49      阅读:397      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
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;
        
    }
}
bubuko.com,布布扣

[Leetcode]-- Valid Palindrome

原文:http://www.cnblogs.com/RazerLu/p/3533654.html

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