Leetcode topics in Java Design Practice class

Source: Internet
Author: User

7.Reverse Integer

The idea of solving problems: Using code that enforces type conversions, first using long, then judging values and then forcing them into int

1  Public classSolution {2      Public intReverseintx) {3         LongReverse_n =0;4          while(X! =0) {5Reverse_n = Reverse_n *Ten+ x%Ten;//Key Code6x = x/Ten;7         }8         if(Reverse_n > Integer.max_value | | Reverse_n <integer.min_value) {9             return 0;Ten         } One         return(int) Reverse_n; A     } -}

9. Palindrome Number

1  Public classSolution {// problem Solving ideas: direct use of directly do reverse topics, if x = = Reverse_x is a palindrome number. 2      PublicBoolean Ispalindrome (intx) {3         if(X <0) {4             return false;5         }6         inty =x;7         Longreverse_x =0;8          while(X! =0) {9reverse_x = reverse_x *Ten+ x%Ten;Tenx = x/Ten; One         } A         //if (x > Integer.max_value | | x < integer.min_value) { -         //return false; -         // } the         if(Y = = (int) {reverse_x) { -             return true; -         } -         return false; +     } -}

      

Leetcode topics in Java Design Practice class

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.