leetcode-9. Palindrome Number
Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could also try reversing an integer. However, if you have solved the problem “Reverse Integer”, you know that the reversed integer might overflow. How would you handle such case?
可以类比leetocde7
public class Solution {
public boolean
isPalindrome(
int x) {
if(x <
0)
return false;
long tmp = x;
long rev =
0;
while(tmp !=
0){
long p = tmp%
10;
tmp /=
10;
rev = rev*
10 + p;
if(rev > Integer.MAX_VALUE);
}
System.
out.println(rev);
if(rev == x)
return true;
return false;
}
}
转载请注明原文地址: https://ju.6miu.com/read-678740.html