GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/python/007_Reverse_Integer.py at master · raghugitrepo/leetcode Expand file tree/ Copy path007_Reverse_Integer.pyMore file actions 34 lines (28 loc) · 688 Bytes / Copy path007_Reverse_Integer.pyFile metadata and controls34 lines (28 loc) · 688 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 class Solution: def reverse(self, x): # https://leetcode.com/problems/reverse-integer/ # flag = True if x < 0 else False # if flag: # x = -x # x = str(x)[::-1] # if flag: # x = "-" + x # value = 2 ** 31 # x = int(x) # if -value <= x < value: # return x # return 0 is_neg = False if x < 0: x = -x is_neg = True res = 0 while x > 0: res *= 10 res += x % 10 x //= 10 if is_neg: res = -res if res < -2**31 or res > 2**31-1: return 0 return res |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |