pub fn reverse_integer(x: i32) -> i32
Expand description

Reverse an integer (32-bit long) and check for overflow.

Exchange front and end digits (not bits) one by one, return zero if overflow

Argument

  • x - 32-bit signed integer to alter

Examples

use leetcode_rust::problems::p000_0xx::p000_007::reverse_integer;
assert_eq!(reverse_integer(-2147483647), 0);
assert_eq!(reverse_integer(123), 321);
assert_eq!(reverse_integer(120), 21);
assert_eq!(reverse_integer(-123), -321);