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
Reprint Please specify source: http://www.cnblogs.com/chruny/p/4798828.html
[Leetcode] (python): 007-reverse Integer