判断回文数
kaikai-sk opened this issue · 2 comments
kaikai-sk commented
class Solution {
public boolean isPalindrome(int x) {
if (x < 0 || (x != 0 && x % 10 == 0)) return false;
int halfReverseX = 0;
while (x > halfReverseX) {
halfReverseX = halfReverseX * 10 + x % 10;
x /= 10;
}
return halfReverseX == x || halfReverseX / 10 == x;
}
}
什么时候会走halfReverseX == x 这条return 路径呢??
Blankj commented
x为偶数长度的数字时,要自己多思考哈
kaikai-sk commented
一时没想出来。
该多吃点核桃补补脑了