[LeetCode-interview algorithm classic-Java implementation] [007-Reverse Integer (Flip Integer)], leetcode -- java

Source: Internet
Author: User

[LeetCode-interview algorithm classic-Java implementation] [007-Reverse Integer (Flip Integer)], leetcode -- java
[007-Reverse Integer (Flip Integer )][LeetCode-interview algorithm classic-Java implementation] [directory indexes for all questions]Original question

Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x =-123, return-321

Theme

Enter an integer to flip it.

Solutions

Calculate the commercial law by finding the remainder.

Code Implementation
Public class Solution {public int reverse (int x) {long tmp = x; // prevent result overflow long result = 0; while (tmp! = 0) {result = result * 10 + tmp % 10; tmp = tmp/10;} // determine if (result <Integer. MIN_VALUE | result> Integer. MAX_VALUE) {result = 0;} return (int) result ;}}
Evaluation Result

Note Please refer to the following link for more information: http://blog.csdn.net/derrantcm/article/details/46938355]

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.