[LeetCode-interview algorithm classic-Java implementation] [009-Palindrome Number (Number of replies)], leetcode -- java

Source: Internet
Author: User

[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.