Skip to content

Commit 1c8b683

Browse files
Add 868_Binary_Gap.py (qiyuangong#23)
Added 868_Binary_Gap Python solution, by @diwansimranbanu
1 parent 1ca0f6e commit 1c8b683

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

python/868_Binary_Gap.py

Lines 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)