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

Source: Internet
Author: User

"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)"

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.