Leetcode 7 整数反转
2019-04-11 22:28
134 查看
Leetcode 7 整数反转
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。
示例 1:
输入: 123
输出: 321
示例 2:
输入: -123
输出: -321
示例 3:
输入: 120
输出: 21
详解:
一道非常基础的题目,没什么太多好说的,关键就在这一行 num = num*10 + x%10
另外需要注意的是在计算中不要让num*10以后发生溢出
class Solution { public int reverse(int x) { int num =0; while(x!=0){ if(Math.abs(num)>Integer.MAX_VALUE/10) return 0; num = num*10+x%10; x = x/10; } return num; } }
相关文章推荐
- (LeetCode每日一刷02)反转整数
- Java&LeetCode 初入门——007. 整数反转
- LeetCode第7题:整数反转 之 先从简单刚起(C++)
- leetcode中文(一) #7反转整数,#77组合
- LeetCode:整数反转(Python版本)
- leetcode 7. Reverse Integer整数反转
- leetcode 7. 反转整数(c++版)
- leetcode——Reverse Integer 反转整数数字(AC)
- 【LeetCode】7. 整数反转
- golang_算法: leetcode_字符串02-整数反转
- LeetCode题解(python)-7. 整数反转
- [leetcode 7] Reverse Integer(整数反转) c函数实现
- Leetcode反转整数
- LeetCode 第七题 反转整数
- (LeetCode)Reverse Integer --- 反转整数
- [Leetcode] reverse integer 反转整数
- 【LeetCode】-7 整数反转
- LeetCode7. 整数反转
- LeetCode 7. Reverse Integer(反转整数)
- [leetcode 7] 整数反转 python