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

Palindrome Number 2015年6月23日

时间:2015-06-23 19:48:42      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

题目:

判断一个数是不是回文数

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

思路:借助上一道求整数逆序的思路,判断逆序后的数和原数是否相等就行。要注意,负数都不是回文数

11506 / 11506 test cases passed.
Status: Accepted
Runtime: 588 ms
Submitted: 0 minutes ago

解答:

public class Solution {
     public boolean isPalindrome(int x) {
        int pal = 0;
        int origin = x;
        if(x<0) {
            return false;
        }
         
        while(x!=0)
        {
            pal = pal*10+x % 10;
            x /= 10;
        }

         
      return pal == origin;
            
     }
    
}

 

Palindrome Number 2015年6月23日

标签:

原文地址:http://www.cnblogs.com/hixin/p/4595951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!