Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 415 Bytes

868.md

File metadata and controls

30 lines (21 loc) · 415 Bytes

Binary Gap

Description

link


Solution

  • bin in python

Code

O(n)

class Solution:
    def binaryGap(self, N: int) -> int:
        s = bin(N)
        res = 0
        i = float('inf')
        for j, n in enumerate(s[2:]):
            if n == '1':
                res = max(res, j - i)
                i = j
        return res