Skip to content

Commit 984d853

Browse files
committed
868
1 parent efb49e8 commit 984d853

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

BIT/868.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Binary Gap
2+
3+
#### Description
4+
5+
[link](https://leetcode.com/problems/binary-gap/)
6+
7+
---
8+
9+
#### Solution
10+
11+
- bin in python
12+
13+
---
14+
15+
#### Code
16+
17+
O(n)
18+
19+
```python
20+
class Solution:
21+
def binaryGap(self, N: int) -> int:
22+
s = bin(N)
23+
res = 0
24+
i = float('inf')
25+
for j, n in enumerate(s[2:]):
26+
if n == '1':
27+
res = max(res, j - i)
28+
i = j
29+
return res
30+
```

0 commit comments

Comments
 (0)