leetcode Reverse Integer
2015-01-26 10:54
399 查看
此题需要注意的地方是处理数字反转后溢出的情况
class Solution { public: int reverse(int x) { if(x==0) return x; int res = 0; int sign = 1; if(x<0) { sign = -1; x = abs(x); } while(x!=0) { if(res>(INT_MAX-x%10)/10) return 0; int digit = x%10; res = res*10 + digit; x = x/10; } return (sign==-1)? -res:res; } };
相关文章推荐
- LeetCode Reverse Integer
- Leetcode在线编程 reverse-integer
- LeetCode:Reverse Integer
- (LeetCode)Reverse Integer --- 反转整数
- LeetCode 7 — Reverse Integer(C++ Java Python)
- LeetCode : Reverse Integer
- LeetCode--Reverse Integer (Cpp,Java,Python)
- LeetCode 7 Reverse Integer(翻转整数)
- Leetcode Reverse Integer
- leetcode: Reverse Integer
- Leetcode Reverse Integer
- leetcode 104: Reverse Integer
- LeetCode 7 Reverse Integer 这道题被血虐
- LeetCode Reverse Integer
- LeetCode(7)Reverse Integer
- LeetCode 7 : Reverse Integer (Java)
- 《leetcode》reverse-integer
- 【leetcode】整型翻转问题integer reverse
- leetcode——Reverse Integer
- leetcode——7—— Reverse Integer可仿溢出