问题:Reverse digits of an integer.
Example1:x = 123, return 321
Example2:x = -123, return -321
Note:
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
分析:输入为int,输出也同为int,需要做的是将原来的int做一个reverse,并且要注意有“-”存在的情况。
结果并不对,回过头检查发现note里有重要的信息:The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.”
32位头符号整数:32位计算机字长,用于表示整数,共有2的32平方个.范围是:-2147483648~2147483648
因此修改代码如下: