#2119
Easy Algorithms A number after a double reversal
Math
82.0% acceptance
Feb 25, 2026
795
47
Reversing an integer means to reverse all its digits.
For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.
Given an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. Return true if reversed2 equals num. Otherwise return false.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn is_same_after_reversals(num: i32) -> bool {
// A double reversal equals the original iff num == 0 OR num has no trailing zeros
num == 0 || num % 10 != 0
}
}