LeetCode记录之9——Palindrome Number

  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;
    }
}
原文地址:https://www.cnblogs.com/vi3nty/p/7468220.html