Reverse Integer

Given a 32-bit signed integer, reverse digits of an integer.

#define INT_MAX     2147483647
#define INT_MIN     (-INT_MAX - 1)

int reverse(int x) {
  
  int y = 0;
  while(x != 0)
  {
     int t = x % 10;
     if(y > INT_MAX /10 || y < INT_MIN / 10)
     {
        return 0;
     }

     y = y * 10 + t;
     x = x/10;
  }
  return y;
    
}

你可能感兴趣的:(Reverse Integer)