Reverse Integer

interview-questions
Tags: #<Tag:0x00007f181efab288>

#1

The comment body goes here.

int Solution::reverse(int A) {
int rev = 0;
while ( A!= 0) {
int rem = A % 10;
A /= 10;
if (rev > INT_MAX/10 || (rev == INT_MAX / 10 && rem > 7)) return 0;
if (rev < INT_MIN/10 || (rev == INT_MIN / 10 && rem < -8)) return 0;
rev = rev * 10 + rem;
}
return rev;
}