add new solutions
This commit is contained in:
parent
ee1868a10e
commit
2012261d3d
7 changed files with 205 additions and 0 deletions
18
solutions/8/q868/solution.go
Normal file
18
solutions/8/q868/solution.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package q868
|
||||
|
||||
func binaryGap(n int) int {
|
||||
maxGap := -1
|
||||
gap := -99
|
||||
for n > 0 {
|
||||
if n%2 == 0 {
|
||||
gap++
|
||||
} else {
|
||||
maxGap = max(maxGap, gap)
|
||||
gap = 0
|
||||
}
|
||||
n >>= 1
|
||||
}
|
||||
return maxGap + 1
|
||||
}
|
||||
|
||||
var _ = binaryGap
|
||||
Loading…
Add table
Add a link
Reference in a new issue