We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3c99b19 commit 31746f8Copy full SHA for 31746f8
Python/reverse-integer.py
@@ -28,10 +28,10 @@ def reverse(self, x):
28
while x:
29
ans = ans * 10 + x % 10
30
x /= 10
31
- return ans
+ return ans if ans <= 2147483647 else 0 # Handle overflow.
32
else:
33
return -self.reverse(-x)
34
35
if __name__ == "__main__":
36
print Solution().reverse(123)
37
- print Solution().reverse(-321)
+ print Solution().reverse(-321)
0 commit comments