[LeetCode-interview algorithm classic-Java implementation] [009-Palindrome Number (Number of replies)], leetcode -- java
[009-Palindrome Number (Number of replies )][LeetCode-interview algorithm classic-Java implementation] [directory indexes for all questions]Original question
Determine whether an integer is a palindrome. Do this without extra space.
Theme
Determine whether a number is a return visit. Do not use extra space.
Solutions
In order not to use extra space, refer to other solutions. The solutions do not seem to use additional parameters in the isPalindrome method, but use method calls, this account consumes more space than an integer and does not meet the requirements of the question. It is a false implementation. Therefore, an additional space is used for this question.
First, the negative number is not a return number, and then the number is reversed. 123 is changed to 321. If the number after conversion is equal, the return number is used.
Code Implementation
Public class Solution {public boolean isPalindrome (int x) {// The negative number is not the value of the return Visit number if (x <0) {return false;} // after the number is reversed, to avoid overflow, use long reverse = 0; int tmp = x; // to evaluate the reverse value while (tmp! = 0) {reverse = reverse * 10 + tmp % 10; tmp/= 10;} // determines whether the return number is return x = reverse ;}}
Evaluation Result
Click the image. If you do not release the image, drag it to a position. After the image is released, you can view the complete image in the new window.
Note
Please refer to the source for reprinting [http://blog.csdn.net/derrantcm/article/details/46951803]
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.