LeetCode 7 Reverse Integer
来源:互联网 发布:图章制作软件下载 编辑:程序博客网 时间:2024/05/22 11:48
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
click to show spoilers.
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.
Update (2014-11-10):
Test cases had been added to test the overflow behavior.
Subscribe to see which companies asked this question
Discuss
水题,只是一定要控制精度,溢出的话就过不了了。
class Solution {public: int reverse(int x) { long res=0; do { res=res*10+x%10; if(res>INT_MAX||res<INT_MIN) return 0; }while(x/=10); return (int)res; }};
- LeetCode 7 - Reverse Integer
- LeetCode(7) Reverse Integer
- leetcode 7REVERSE 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
- 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
- Hibernate的常用配置
- 第五周 项目一 三角形类雏形(4)
- 稳定排序和不稳定排序
- Ubuntu 14.04.2解决域名解析慢的问题
- hdu 2224 The shortest path 双调欧几里得旅行商问题(动态规划)
- LeetCode 7 Reverse Integer
- MATLAB 教程
- Jmeter访问DB URL及driver
- C#将Excel数据表导入SQL数据库的两种方法
- hdu1561The more, The Better【树型dp 01背包】
- 增强for循环
- 第五周 项目一 三角形类雏形(5)
- java char转换成string string转换成char
- Java之路