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 · raghugitrepo/leetcode

Expand file tree

/

007_Reverse_Integer.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
34 lines (28 loc) · 688 Bytes
/

007_Reverse_Integer.py

Copy path

File metadata and controls

34 lines (28 loc) · 688 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
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.