7. 整数反转
题解
使用 x % 10 取出个位数
执行用时:1 ms, 在所有 Java 提交中击败了100.00%的用户 内存消耗:35 MB, 在所有 Java 提交中击败了99.82%的用户
class Solution {public int reverse(int x) {int res = 0;while (x != 0) {if (res < Integer.MIN_VALUE / 10 || res > Integer.MAX_VALUE / 10)return 0;res = (res * 10) + (x % 10);x /= 10;}return res ;}}
