Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
1 |
Input: 123 |
Example 2:
1 |
Input: -123 |
Example 3:
1 |
Input: 120 |
数字反转。
分析:题目不难,唯一需要注意的就是反转后是否越界的问题,所以不能定义int的变量接收反转后的值,应该用long,详细代码如下:
1 |
class { |
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
1 |
Input: 123 |
Example 2:
1 |
Input: -123 |
Example 3:
1 |
Input: 120 |
数字反转。
分析:题目不难,唯一需要注意的就是反转后是否越界的问题,所以不能定义int的变量接收反转后的值,应该用long,详细代码如下:
1 |
class { |
近期评论