@zimenglan
2014-11-29T04:02:14.000000Z
字数 377
阅读 1037
Reverse Integer
leetcode
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321
class Solution {public:int reverse(int x) {// may be overflow when inverse the inputlong long base = 1L;int Max_Int = (int)((base << 31) - 1);int Min_Int = (int)(0 - (base << 31));long long res = 0;while(x != 0) {res = res * 10 + (x % 10);x = x / 10;}if(res > Max_Int || res < Min_Int) {return 0;}return (int)res;}};
