# [Leetcode] (python): 007-reverse Integer

Source: Internet
Author: User

Source of the topic:

https://leetcode.com/problems/reverse-integer/

Test Instructions Analysis:

The problem is simple, that is, a number reversal, 123 change 321,-123 321.

Topic Ideas:

The topic is very simple, first the number of absolute X, then x%10 take the last one, and then ans = ans*10 + x%10, plus the last one. Then x removes the last one. Know x = 0. Note that when you exceed the 32-bit int type, the setting is equal to 0.

Code (Python):
`1 classsolution (object):2     defreverse (self, x):3         """4 : Type X:int5 : Rtype:int6         """7Positive =True8         ifX <0:9Positive =FalseTenx =ABS (x) OneAns =0 A          whileX >0: -Ans = ans * + x% 10 -X//= 10 the         ifAns > 2147483647: -             return0 -         if  notPositive: -             return-1*ans +         returnAns`
View Code

[Leetcode] (python): 007-reverse Integer

Related Keywords:
Related Article

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.