Skip to content

Commit 9391cdd

Browse files
author
nhimanshujain
committed
Added solution to Leetcode Question - 7 | Reverse Integer
1 parent 1e0efba commit 9391cdd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

0007/reverse_integer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class Solution:
22
def reverse(self, x: int) -> int:
33
val = 0
4-
pro = 1 if x>0 else -1
4+
pro = 1 if x > 0 else -1
55
x = abs(x)
66
while x:
7-
val=val*10+x%10
8-
x//=10
9-
return val*pro if (val<=2**31 -1 and val>=-2**31 ) else 0
7+
val = val * 10 + x % 10
8+
x //= 10
9+
return val * pro if (val <= 2 ** 31 - 1 and val >= -2 ** 31 ) else 0

0 commit comments

Comments
 (0)