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
|
||||
12
solutions/16/q1689/solution.go
Normal file
12
solutions/16/q1689/solution.go
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Package q1689 implements a solution for https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/
|
||||
package q1689
|
||||
|
||||
func minPartitions(n string) int {
|
||||
maxDigit := 0
|
||||
for i := range len(n) {
|
||||
maxDigit = max(maxDigit, int(n[i]-'0'))
|
||||
}
|
||||
return maxDigit
|
||||
}
|
||||
|
||||
var _ = minPartitions
|
||||
Loading…
Add table
Add a link
Reference in a new issue