https://leetcode.com/problems/palindrome-number/description/
解题思路:
- 反向相乘去得到目标值
reverse = reverse * 10 + temp % 10;
temp /= 10;
代码:
class Solution {
public boolean isPalindrome(int x) {
if(x < 0) return false;
int reverse = 0, temp = x;
while(temp > 0){
reverse = reverse * 10 + temp % 10;
temp /= 10;
}
return reverse == x;
}
}
网友评论