LeetCode #7

Reverse digits of an integer.


Example1: x = 123, return 321
Example2: x = -123, return -321

Note The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.

Pseudo code

  1. get absolute value
  2. split digits to an array
  3. reverse array
  4. join reversed array back to string
  5. parse to number
  6. test original sign
  7. return reversed value with sign accordingly


See the Pen 7. Reverse Integer by Cherry Wang (@chryw) on CodePen.