Degree
Easy ★ (*´╰╯`๓)♬
Description:
Given a 32-bit signed integer, reverse digits of an integer.
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.
Example1:
1 | Input: 123 |
Example2:
1 | Input: -123 |
Example3:
1 | Input: 120 |
Ideas
- 模十法,将各位的数字依次往最高位升
- 初始为负数的依然为负数形式
- 当数字大小茶超过2^32的时候,就返回0
Code
1 | var reverse = function(x) { |