Determine whether an integer is a palindrome. Do this without
extra space.
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
public class Solution { public boolean isPalindrome( int x) { //负数不是回文数字 if (x< 0 ){ return false ; } //0是回文数字 else if (x== 0 ){ return true ; } //如果x为正数 else { int tmpx = x; int newx = 0 ; //翻转x while (tmpx> 0 ){ newx = newx* 10 + (tmpx% 10 ); tmpx = tmpx/ 10 ; } //判断翻转后的newx和x是否相同 if (newx==x){ return true ; } return false ; } } }
|