Palindrome Number

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

 1 public class Solution {
 2     public boolean isPalindrome(int x) {
 3         if(x<0) return false;
 4         int div = 1;
 5         while(x/div>=10){
 6             div *=10;
 7         }
 8         while(x>0){
 9             if(x/div!=x%10) return false;
10             x = x%div/10;
11             div /=100;
12         }
13         return true;
14     }
15 }
View Code

 consider x<0 

x/d>=10

必须用x/d不然int 溢出

posted @ 2014-02-07 03:49  krunning  阅读(102)  评论(0编辑  收藏  举报