A Number After a Double Reversal

The problem is asking us to reverse an integer twice and check if the result equals the original integer.

Python solution:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class Solution:
    def isSameAfterReversals(self, num: int) -> bool:
        # Reverse num to get reversed1
        reversed1 = int(str(num)[::-1])

        # Reverse reversed1 to get reversed2
        reversed2 = int(str(reversed1)[::-1])

        # Check if reversed2 equals num
        return reversed2 == num

In this solution, we first convert the integer num to a string and then reverse it using slicing ([::-1]). This gives us reversed1. We convert reversed1 back to an integer and then repeat the process to get reversed2. Finally, we check if reversed2 equals num.

This solution works because it correctly reverses the integer twice and then checks if the result equals the original integer. The time complexity is O(n), where n is the number of digits in num.