Description
Given a 32-bit signed integer, reverse digits of an integer.
Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−2^31, 2^31 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
Example
Input: 120
Output: 21
boudary
input:7463847412 output:2147483647
input:8463847412 output:0
input:-8463847412 output:-2147483648
input:-9463847412 output:0
my solution:
1 | # 80ms use 1hour 30min |
Best
1 | # 48 ms |
Analyse
对 string 与int 之间的转换不熟悉,对切片操作不熟悉,导致用了大量的计算来造轮子。
时间上用计算好的数据来替代会节约运行时间。