From 943b189b33ad08342fb7aaf4d6580d2184aaf54f Mon Sep 17 00:00:00 2001 From: chakyam Date: Fri, 21 Sep 2018 00:06:06 +0800 Subject: [PATCH] Update solution 007 [Python3] --- solution/007.Reverse Integer/README.md | 0 solution/007.Reverse Integer/Solution.java | 0 solution/007.Reverse Integer/Solution.py | 20 ++++++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 solution/007.Reverse Integer/README.md create mode 100644 solution/007.Reverse Integer/Solution.java create mode 100644 solution/007.Reverse Integer/Solution.py diff --git a/solution/007.Reverse Integer/README.md b/solution/007.Reverse Integer/README.md new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/solution/007.Reverse Integer/Solution.java b/solution/007.Reverse Integer/Solution.java new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/solution/007.Reverse Integer/Solution.py b/solution/007.Reverse Integer/Solution.py new file mode 100644 index 0000000000000..83325e1c649b4 --- /dev/null +++ b/solution/007.Reverse Integer/Solution.py @@ -0,0 +1,20 @@ +class Solution: + def reverse(self, x): + """ + :type x: int + :rtype: int + """ + if x==0: + return 0 + y=str(abs(x)) + y=y[::-1] + y=int(y) + if x<0: + tmp=-y + else: + tmp=y + + if tmp>=2**31-1 or tmp<-(2**31): + return 0 + else: + return tmp \ No newline at end of file