https://leetcode.com/problems/reverse-integer/description/
輸入: 32位有符號 int
輸出: 逆序
思路:
循環(huán)取余就可以實現(xiàn)了,需要注意溢出的情況
class Solution {
public int reverse(int x) {
int t = x;
int num = 0;
while(t!=0){
int temp = num*10 + t%10;
if((temp-t%10)/10 != num){
return 0;
}
num = temp;
t=t/10;
}
return num;
}
}