luoheng
10/11/2019 - 2:06 PM

binaryGap

func binaryGap(N int) int {
    s, ms := -1, -1
    for N != 0 {
        if (N&1) != 0 {
            if s > ms {
               ms = s
            }
            s = 0
        } else if s != -1 {
            s++
        }
        N >>= 1
    }
    return ms + 1
}