One minute
Leetcode 2119
The idea of this solution is that any number that has a 0
at the end will result in a different number after reversed twice.
This is shown using the numbers:
3210
reversed equals123
which reversed again equals321
31000
reversed equals13
which reversed again equals31
The only exception for this rule in the number 0
. because 0
zero reversed any amount of times equals 0
.
func isSameAfterReversals(num int) bool {
return num == 0 || num % 10 != 0
}
Read other posts