给定一个 32 位有符号整数,将整数中的数字进行反转。

只要考虑整数超过32位时的溢出处理就行了,很简单

c++:

class Solution {
public:
    int reverse(int x) {
        long long ans=0;
        const int   maxint=0x7fffffff;
        const int   minint=0x80000000;
        while(x!=0)
        {
            ans=ans*10+x%10;
            x=x/10;
        }
        if(ans<minint||ans>maxint)
            ans=0;
        return ans;
        
    }
};