add new solutions
This commit is contained in:
parent
ee1868a10e
commit
2012261d3d
7 changed files with 205 additions and 0 deletions
20
solutions/16/q1680/solution.go
Normal file
20
solutions/16/q1680/solution.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Package q1680 implements a solution for https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/
|
||||
package q1680
|
||||
|
||||
const MOD int = 1e9 + 7
|
||||
|
||||
func concatenatedBinary(n int) int {
|
||||
ret := 0
|
||||
binLen := 1
|
||||
|
||||
for c := 1; c <= n; c++ {
|
||||
if 1<<binLen <= c {
|
||||
binLen++
|
||||
}
|
||||
|
||||
ret = (ret<<binLen + c) % MOD
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
var _ = concatenatedBinary
|
||||
Loading…
Add table
Add a link
Reference in a new issue