1,翻转每一位数字即可,原理比较简单,我们直接来看图分析
import java.util.*;
public class Solution {
/**
*
* @param x int整型
* @return int整型
*/
public int reverse (int x) {
long result = 0;
while (x != 0) {
result = result * 10 + x % 10;
x = x / 10;
}
if (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) {
return 0;
}
return (int)result;
}
} 


京公网安备 11010502036488号