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 · tairen99/leetcode Expand file tree/ Copy path007_Reverse_Integer.pyMore file actions 39 lines (37 loc) · 959 Bytes / Copy path007_Reverse_Integer.pyFile metadata and controls39 lines (37 loc) · 959 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 35 36 37 38 39 class Solution: # @return an integer # def reverse(self, x): # max_int = 2147483647 # if x == 0: # return 0 # isPos = True # if x < 0: # x *= (-1) # isPos = False # ltemp = [] # while x != 0: # temp = x % 10 # ltemp.append(temp) # x /= 10 # result = 0 # # the main solution # for t in ltemp: # result = result * 10 + t # if result > max_int: # result = 0 # if isPos: # return result # else: # return -1 * result def reverse(self, x): # Note that in Python -1 / 10 = -1 res, isPos = 0, 1 if x < 0: isPos = -1 x = -1 * x while x != 0: res = res * 10 + x % 10 if res > 2147483647: return 0 x /= 10 return res * isPos |
| 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. |