题目
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;
}
};
网友评论