首页 > 其他 > 详细

LeetCode记录之9——Palindrome Number

时间:2017-09-02 22:57:23      阅读:241      评论:0      收藏:0      [点我收藏+]

  LeetCode真是个好东西,本来闲了一下午不想看书,感觉太荒废时间了就来刷一道题。能力有限,先把easy的题目给刷完。


  Determine whether an integer is a palindrome. Do this without extra space.

   确定一个整数是否是回文。 做这个没有额外的空间。


  这道题毕竟是easy级别的,花了大概5分钟就写出来了。我的思路就是判断回文要首尾一一对照么,如果把int转换成string类型的话比较字符就方便多了。

class Solution {
    public boolean isPalindrome(int x) {
        boolean isAbove=true;
        if(x<0){
            return false;
        }
        String num=x+"";
        int length=num.length();
        for(int i=0;i<length/2;i++){
            if(num.charAt(i)!=num.charAt(length-i-1))
                return false;
        }
        return true;
    }
}

 

LeetCode记录之9——Palindrome Number

原文:http://www.cnblogs.com/vincentme/p/7468220.html

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