leetcode9. 回文数

问题连接:9. 回文数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class  {

* 判断一个整数是否是回文数字 121,12321是,123 1234不是
*
* @param x
* @return
*/
public static boolean isPalindrome(int x) {
int origin = x;
int result = 0;

if (x < 0) return false;

// 123
while (x > 0) {
int temp = x % 10;
x = x / 10;
result = result * 10 + temp;
}

if (result == origin) return true;
return false;
}
}