Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added 868_Binary_Gap.py
added 868_Binary_Gap.py
  • Loading branch information
diwansimranbanu authored Oct 3, 2020
commit 7572dadef61498c248a17da79d2f0120ee19d3e2
14 changes: 14 additions & 0 deletions python/868_Binary_Gap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def binaryGap(self, n: int) -> int:
current= 1
last1 = -1
out = 0
while n > 0:
if n%2 == 1:
if last1 >= 1:
out = max(out, current - last1)
last1 = current
current += 1
n = n//2
return(out)