Given a 32-bit signed integer, reverse digits of an integer.
Example 1:12Input: 123Output: 321
Example 2:12Input: -123Output: -321
Example 3:12Input: 120Output: 21
Note:
Assume we are dealing with an environment which could only hold integers within the 32-bit signed integer range. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
解法1:
这里用到了其中一种判断是否overflow的办法,就是先存下变化之前的数,然后变化之后做相同的操作看看是否和原来的数字一致。如果不相等则说明这个操作overflow了。
|
|