A Number After a Double Reversal - Problem
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.
Input & Output
Example 1 — Number Without Trailing Zeros
$
Input:
num = 526
›
Output:
true
💡 Note:
First reversal: 526 → 625. Second reversal: 625 → 526. Since 526 == 526, return true.
Example 2 — Number With Trailing Zero
$
Input:
num = 1800
›
Output:
false
💡 Note:
First reversal: 1800 → 81 (trailing zeros lost). Second reversal: 81 → 18. Since 18 ≠ 1800, return false.
Example 3 — Single Digit
$
Input:
num = 0
›
Output:
true
💡 Note:
First reversal: 0 → 0. Second reversal: 0 → 0. Since 0 == 0, return true.
Constraints
- 0 ≤ num ≤ 106
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given integer num
2
Double Reverse
Reverse twice and check equality
3
Pattern
Numbers with trailing zeros always fail
Key Takeaway
🎯 Key Insight: Numbers with trailing zeros always fail double reversal because leading zeros are dropped
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code