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 — Add 868_Binary_Gap.py (#23) · dungquoctrinh/leetcode@1c8b683

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • python
    • 868_Binary_Gap.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎python/868_Binary_Gap.py‎

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def binaryGap(self, n: int) -> int:
3+
current= 1
4+
last1 = -1
5+
out = 0
6+
while n > 0:
7+
if n%2 == 1:
8+
if last1 >= 1:
9+
out = max(out, current - last1)
10+
last1 = current
11+
current += 1
12+
n = n//2
13+
return(out)
14+

0 commit comments

Comments
0 (0)
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.