"009-palindrome number (palindrome)"
" leetcode-interview algorithm classic-java Implementation" "All topic Directory Index"
Original title
Determine whether an integer is a palindrome. Do this without extra spaces.
The main effect of the topic
To determine whether a number is a return word, do not use additional space.
ideas for solving problems
In order not to use additional space and refer to other resolutions, those solutions seem to use no extra parameters in the Ispalindrome method, but use the method call, which consumes more space than an integer, does not meet the requirements of the problem, is a false implementation, So the subject still uses an extra space for implementation.
First of all, negative numbers are not palindrome numbers, followed by a reversal of the number, 123 to 321 so, if the transformation of the number of equal description is palindrome number.
Code Implementation
public class Solution {public
boolean ispalindrome (int x) {
//negative numbers are not return numbers
if (x < 0) {returning
false;
//number reversal value, in order not to use overflow using long
long reverse = 0;
int tmp = x;
Reverse value while
(tmp!= 0) {
reverse = reverse * + tmp%;
TMP/=
}
Judge whether it is palindrome number return
x = = reverse;
}
Evaluation Results
Click on the picture, the mouse does not release, drag a position, released in a new window to view the full picture.
Special Notes Welcome reprint, Reprint please indicate the source "http://blog.csdn.net/derrantcm/article/details/46951803"