Leetcode--reverse Integer

Source: Internet
Author: User

Reverse digits of an integer.

EXAMPLE1:X = 123, return 321
example2:x = -123, return-321

Problem Description: The entire number of 1000-bit reversed-order output.

Note Special cases:

1) Overflow condition: To check for Overflow/underflow, we could check if RET > 214748364 or ret <–214748364 before multiplying by Need to check if ret = = 214748364, why? On the other hand

2) positive numbers, negative numbers in addition to more than 10 10 of the situation;

3) 10,100 Such a number in reverse order can be used in general program processing.

Code:

 Public classSolution { Public intReverseintx) {intMax =Integer.max_value; intMin =Integer.min_value; Longres = 0;  while(x!=0){            intn = x%10; Res= Res *10 +N; X= X/10; if(Res>max | | res<min)return0; }        intRes1 = (int) Res; returnres1; }}

Leetcode--reverse Integer

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.