刷LeetCode(7)——Reverse Integer
2017-11-09 23:18
218 查看
刷LeetCode(7)——Reverse Integer
Code it now !https://leetcode.com/problems/reverse-integer/description/Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123 Output: 321
Example 2:
Input: -123 Output: -321
Example 3:
Input: 120 Output: 21
Note:
Assume we are dealing with an environment which could only hold integers within the 32-bit signed integer range. 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 res = 0; while(x) { res = res*10 + x%10; x /= 10; } return (res<INT_MIN || res>INT_MAX) ? 0 : res; } };
相关文章推荐
- 【python】【leetcode】【算法题目7—Reverse Integer】
- 007 Reverse Integer [Leetcode]
- LeetCode: Reverse Integer
- LeetCode Reverse Integer 带考虑第二种特殊情况
- leetcode Reverse Integer & Palindrome Number
- LeetCode——Reverse Integer(逆置一个整数)
- LeetCode——Reverse Integer
- LeetCode : 7 Reverse Integer C++
- [LeetCode] Reverse Integer 解题报告
- Reverse Integer leetcode--JavaScript
- LeetCode Reverse Integer
- LeetCode Reverse Integer
- LeetCode (Easy Part) Reverse Integer
- leetcode_07_Reverse Integer (easy)
- Leetcode|Reverse Integer(string转char*总结)
- Reverse Integer leetcode python
- [LeetCode 7]Reverse Integer(处理整数溢出)
- LeetCode Reverse Integer
- Reverse Integer--LeetCode(Java)
- LeetCode Reverse Integer(C)