Skip to content

Commit 0e36cfa

Browse files
committed
Added reverse_integer
1 parent b24d2ef commit 0e36cfa

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

reverse_integer/solution.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
# @return an integer
3+
def reverse(self, x):
4+
t = 0
5+
if x > 0:
6+
positive = True
7+
else:
8+
positive = False
9+
x = -x
10+
while x != 0:
11+
t = 10 * t + x % 10
12+
x /= 10
13+
return t if positive else -t

0 commit comments

Comments
 (0)