[LeetCode]Reverse Integer
2013-10-10 02:39
375 查看
这题啥也不说了,简单…… 记一下代码。
要通过测试,主要就是处理一下正负号。
要通过测试,主要就是处理一下正负号。
class Solution { public: int reverse(int x) { // Note: The Solution object is instantiated only once and is reused by each test case. int result = 0; int sign = x < 0 ? -1 : 1; x *= sign; while (x > 0) { /*if (result == 214748364) { if (sign == -1) { if (x > 8) return 0; } else { if (x > 7) return 0; } } else if (result > 214748364) return 0;*/ result = (result * 10) + (x % 10); x /= 10; } result *= sign; return result; } };
相关文章推荐
- Leetcode 7. Reverse Integer
- LeetCode - E - Reverse Integer
- LeetCode7--Reverse Integer
- LeetCode:Reverse Integer
- 【leetcode】【7】Reverse Integer
- LeetCode 007 Reverse Integer
- Leetcode 7 Reverse Integer
- leetcode第七题--Reverse Integer
- 【leetcode c++】Reverse Integer
- leetCode(62)-Reverse Integer
- leetcode-- Reverse Integer
- leetcode-7-Reverse Integer
- LeetCode之 Reverse Integer
- [leetcode]Reverse Integer
- leetcode - Reverse Integer
- 【Leetcode】【python】Reverse Integer
- 【LeetCode with Python】 Reverse Integer
- leetcode_Reverse Integer
- 【Leetcode】Reverse Integer
- leetcode 8. 将整数的位数反序 Reverse Integer