Leetcode 7 Reverse Integer
2016-09-07 15:00
363 查看
题目描述:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
最需注意的就是倒置后的整形溢出问题,当>2147483647和<-2147483647时,返回0
class Solution {
public:
int reverse(int x) {
long result = 0;
while(x != 0)
{
result = result * 10 + x % 10;
x = x / 10;
}
if(result > INT_MAX || result < INT_MIN)
return 0;
else
return result;
}
};
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
最需注意的就是倒置后的整形溢出问题,当>2147483647和<-2147483647时,返回0
class Solution {
public:
int reverse(int x) {
long result = 0;
while(x != 0)
{
result = result * 10 + x % 10;
x = x / 10;
}
if(result > INT_MAX || result < INT_MIN)
return 0;
else
return result;
}
};
相关文章推荐
- [LeetCode]Reverse Integer
- leetcode(3)7.Reverse Integer
- LeetCode:Reverse Integer
- Leetcode 7 - Reverse Integer
- LeetCode 7 Reverse Integer
- Reverse Integer [LEETCODE]
- 【LeetCode】LeetCode——第7题:Reverse Integer
- [LeetCode]Reverse Integer
- 【leetcode】Reverse Integer
- [leetcode 7] Reverse Integer
- LeetCode-Reverse Integer
- 【leetcode with java】7 Reverse Integer
- Leetcode代码学习周记——Reverse Integer
- [Leetcode]-Reverse Integer
- LeetCode——Reverse Integer
- LeetCode 7 - Reverse Integer
- [LeetCode]Reverse Integer
- [LeetCode]007-Reverse Integer
- leetcode: (7) Reverse Integer
- LeetCode 7 Reverse Integer