Loading RustViz Engine...
Reverse digits of a 32-bit signed integer using checked arithmetic.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn reverse(mut x: i32) -> Option<i32> {
let mut rev: i32 = 0;
while x != 0 {
let pop = x % 10;
x /= 10;
rev = rev.checked_mul(10)?.checked_add(pop)?;
}
Some(rev)
}