Reverse digits of an integer.
1 public class Solution { 2 public int reverse(int x) { 3 4 long lx = x; 5 long nx = 0; 6 while (lx != 0) { 7 nx = nx * 10 + lx % 10; 8 lx /= 10; 9 } 10 11 return (int)((nx > Integer.MAX_VALUE || nx < Integer.MIN_VALUE) ? 0 : nx); 12 } 13 }

浙公网安备 33010602011771号