#include <iostream>
#include <cmath>
using namespace std;
#define INIT_MAX pow(2, 31)-1
#define INIT_MIN -pow(2, 31)
class Solution{
public:
int reverse(int x){
long long y = 0;
while(x!=0){
int pop = x%10;
y = y * 10 + pop;
x /= 10;
}
if(y > INIT_MAX ||y < INIT_MIN)
return 0;
else
return y;
}
};
int main()
{
Solution sol;
cout<<INIT_MAX<<endl;
int result = sol.reverse(1534236469);
cout << result << endl;
return 0;
}
1.LeetCode中#include语句可以不写, main()函数也不写;
2.#define INIT_MAX pow(2, 31)-1是必须的,弄清这个-1的位置;
3.负数对10取余或者整还是负数 ;
4.使用pow需要#include<cmath>,c的意思是c语言中也有,python中用2**31来计算。