All problems
Reverse Integer
Problem
Reverse the digits of a signed 32-bit integer and return the result, or 0 if the reversed value would overflow beyond the range from minus 2 to the 31st power through 2 to the 31st power minus 1.
Reverse the absolute value digit by digit and reapply the sign. Trailing zeros become leading zeros and disappear.
Hint
Check the final reversed value against the 32-bit bounds after applying the sign.
Test cases
case 1
in: [123]
expected: 321
case 2
in: [-123]
expected: -321
case 3
in: [120]
expected: 21
case 4
in: [0]
expected: 0
case 5
in: [1534236469]
expected: 0
Starter codePython
def reverse_integer(x):
# Your code here
pass5 test cases · run your code against them in the editor