40. Reverse Integer FROM Leetcod
2017-03-20 本文已影响7人
时光杂货店
题目
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
频度: 3
解题之法
class Solution {
public:
int reverse(int x) {
long rev= 0;
while( x != 0){
rev= rev*10 + x % 10;
x= x/10;
if( rev > INT_MAX || rev < INT_MIN)
return 0;
}
return (int) rev;
}
};