Skip to content

Commit baa2d66

Browse files
Added reverse-integer
1 parent c0590ac commit baa2d66

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

reverse_integer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def reverse(self, x: int) -> int:
3+
if x == 0:
4+
return 0
5+
elif x < 0:
6+
s = -1
7+
else:
8+
s = 1
9+
x = list(str(x * s))
10+
x.reverse()
11+
res = int("".join(x))
12+
return res * s if res < 0x7fffffff else 0

0 commit comments

Comments
 (0)