
Reverse Integer

Reverse the digits of a given integer. For instance, 1234
should become 4321
. For negative integers, the sign should remain in the front; e.g., -123
becomes -321
.
Input: Integer (int).
Output: Integer (int).
Examples:
assert reverse_digits(1234) == 4321 assert reverse_digits(0) == 0 assert reverse_digits(-123) == -321 assert reverse_digits(5) == 5
How it’s used: this function can be utilized in various algorithmic challenges, number-based puzzles, and certain numerical calculations.
Precondition:
- −109 ≤ num ≤ 109.