Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Reverse Integer by kisungch
def reverse_digits(num: int) -> int:
num = str(num)
return int('-' + num[1:][::-1]) if num[0] == '-' else int(num[::-1])
print("Example:")
print(reverse_digits(32))
# These "asserts" are used for self-checking
assert reverse_digits(1234) == 4321
assert reverse_digits(0) == 0
assert reverse_digits(-123) == -321
assert reverse_digits(5) == 5
assert reverse_digits(-9) == -9
assert reverse_digits(100) == 1
assert reverse_digits(-100) == -1
assert reverse_digits(54321) == 12345
assert reverse_digits(1111) == 1111
assert reverse_digits(987654321) == 123456789
print("The mission is done! Click 'Check Solution' to earn rewards!")
Oct. 3, 2023