Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Created September 8, 2023 14:27
Show Gist options
  • Select an option

  • Save codeperfectplus/a367c7c4a108f32c97c3fc564b92bd97 to your computer and use it in GitHub Desktop.

Select an option

Save codeperfectplus/a367c7c4a108f32c97c3fc564b92bd97 to your computer and use it in GitHub Desktop.
class Solution:
def reverse(self, x: int) -> int:
a = 0
if x >= 0:
a = int(str(x)[::-1])
elif x < 0:
a = -1 * int(str(abs(x))[::-1])
if a >= 2**31-1 or a <= -2**31:
return 0
return a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment