用c++写的时候注意处理溢出。
class Solution { public: int reverse(int x) { long long result=0; int divided, reminder; divided = x; reminder = 0; while(divided) { reminder = divided%10; divided = divided/10; result = result*10 + reminder; } //处理溢出情况 if(result >= -pow(2,31) && result <= pow(2, 31)-1) { return int(result); } return 0; } };