description:
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123
Output: 321
Example 2:
Input: -123
Output: -321
Example 3:
Input: 120
Output: 21
my answer:
class Solution {
public:
int reverse(int x) {
int res = 0;
while(x!=0){
if(abs(res) > INT_MAX/10) return 0;
res = res*10 + x%10; //this forum is important and i can't get it before i saw it ....
x /= 10;
}
return res;
}
};
relative point get√:
hint :
关键在于处理溢出情况