[Leetcode]7. Reverse Integer
来源:互联网 发布:人工智能电影讲什么 编辑:程序博客网 时间:2024/06/05 02:02
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
click to show spoilers.
Have you thought about this?
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!
If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
class Solution {public: int reverse(int x) { long long r = 0; long long t = x; t = t > 0 ? t : -t; for (; t; t /= 10) r = r * 10 + t % 10; bool sign = x > 0 ? false : true; if ( r > 2147483647 || (sign && r > 2147483648)) return 0; else if (sign) return -r; else return r; }};
0 0
- [LeetCode]7.Reverse Integer
- LeetCode 7. Reverse Integer
- LeetCode --- 7. Reverse Integer
- LeetCode 7.Reverse Integer
- [Leetcode] 7. Reverse Integer
- [Leetcode]7.Reverse Integer
- LeetCode 7.Reverse integer
- [LeetCode] 7.Reverse Integer
- 7. Reverse Integer LeetCode
- leetcode 7. Reverse Integer
- leetcode 7. Reverse Integer
- leetcode 7. Reverse Integer
- Leetcode 7. Reverse Integer
- 【LeetCode】7.Reverse Integer
- LeetCode 7. Reverse Integer
- LeetCode *** 7. Reverse Integer
- LeetCode 7. Reverse Integer
- LeetCode-7. Reverse Integer
- 杂花生树(二)
- 从无到有——简单的个人博客(一)
- Store metadata on a configuration drive
- 《linux基础学习》之特点、历史、vi编辑器的使用
- MSP 比较器分析
- [Leetcode]7. Reverse Integer
- 15. 3Sum
- 包依赖关系处理
- 10016---关于重定向
- linux shell 编程(一)
- mac下安装tensorflow
- Training2:位操作训练
- MySQL5.7 触发器
- HDU 5318 The Goddess Of The Moon(矩阵快速幂)