Given a 32-bit signed integer, reverse digits of an integer.題目要求咱們給出一個數的翻轉數
Example 1:
Input: 123
Output: 321
Example 2:
Input: -123
Output: -321
Example 3:
Input: 120
Output: 21git
public int reverse(int x) { long res = 0; while(x != 0){ int tail = x % 10; res = res*10 + tail; if(res > Integer.MAX_VALUE || res < Integer.MIN_VALUE){ return 0; } x = x/10; } return (int)res; }