Q7. Reverse Integer
Last updated
Was this helpful?
Last updated
Was this helpful?
直达:
iven a 32-bit signed integer, reverse digits of an integer.
Example 1:
Example 2:
Example 3:
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.
保存正负号后使用绝对值进行运算。
使用 %10取个位,使用 /10进行右移1位。
使用长整型保存结果(Python不用)以便进行溢出判断。