"009-palindrome number (palindrome)"
"leetcode-Interview algorithm classic-java Implementation" "All topics Directory Index"
Original Question
Determine whether an integer is a palindrome. Do this without extra space.
Main Topic
Determine if a number is a return count, and do not use extra space.
Thinking of solving problems
In order not to use additional space, referring to other solutions, the solution seems to be in the Ispalindrome method does not use the extra parameters, but the use of method calls, which consumes more space than an integer, and does not meet the requirements of the topic, is a false implementation, So the subject still takes 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 converted number equals the palindrome number.
Code Implementation
Public class solution { Public BooleanIspalindrome (intx) {//Negative number is not a return if(X <0) {return false; }//Number reversal value, in order not to use overflow with long Long Reverse=0;intTMP = x;//Seek the value after reversal while(TMP! =0) {Reverse=Reverse*Ten+ tmp%Ten; TMP/=Ten; }//Judging whether it is a palindrome number returnx = =Reverse; }}
Evaluation Results
Click on the picture, the mouse does not release, drag a position, release after the new window to view the full picture.
Special Instructions
Welcome reprint, Reprint please indicate the source "http://blog.csdn.net/derrantcm/article/details/46951803"
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"leetcode-Interview algorithm classic-java Implementation" "009-palindrome Number (palindrome)"