"Leetcode-Interview algorithm classic-java Implementation" "009-palindrome Number (palindrome)" __ Code

Source: Internet
Author: User
"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"

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.