text: /* 7. Reverse Integer
   * Reverse digits of an integer.
   *
   * Example1: x = 123, return 321
   * Example2: x = -123, return -321
   *
   * click to show spoilers.
   *
   * Note:
   * The input is assumed to be a 32-bit signed integer. Your function should
   * return 0 when the reversed integer overflows.
   */
  class Solution {
    public:
      int reverse(int x) {
        long long ret = 0;
        while (x != 0) {
          ret = ret * 10 + x % 10;
          x /= 10;
        }
        if (ret > INT_MAX || ret < INT_MIN)
          return 0;
        return ret;
      }
  };
  
  