Reverse digits of an integer.

时间:2023-03-09 15:56:29
Reverse digits of an integer.
class Solution {
public:
    int reverse(int x) {
       ;//long 是怕中间过程溢出
        <<,max=-min-){
            ans=ans*+x%;
            x=x/;
        }
        if(ans>max||ans<min)
            ;
        return ans;
    }
};

注释:

  这是进制转换问题。

  转化过程中一定要考虑溢出。

  清楚各种类型的表示范围。

附 

32位平台:

unsigned   int   0~4294967295  
int    -2147483648~2147483647 (-2^31~(2^31-1))//补码比原码多表示1个数
unsigned long 0~4294967295
long   -2147483648~2147483647
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
unsigned long long的最大值:1844674407370955161

__int64的最大值:9223372036854775807
__int64的最小值:-9223372036854775808
unsigned __int64的最大值:18446744073709551615