GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/python/007_Reverse_Integer.py at master · frank0712/leetcode

Expand file tree

/

007_Reverse_Integer.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
39 lines (37 loc) · 959 Bytes
/

007_Reverse_Integer.py

Copy path

File metadata and controls

39 lines (37 loc) · 959 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.