[LeetCode]#2119. A Number After a Double Reversal

  • For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.
Input: num = 526
Output: true
Explanation: Reverse num to get 625, then reverse 625 to get 526, which equals num.
  1. Convert input to string format and reverse it
  2. Convert it to int format.
  3. Convert it to a string format and reverse it.
  4. If input equal converted result, return pass.
  5. Else, return Fail.
class Solution:
def isSameAfterReversals(self, num):
temp=str(num)
temp=int(temp[::-1])
temp=str(temp)
temp=temp[::-1]
if int(temp) ==num:
return True
else:
return False

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.