add new solutions
This commit is contained in:
parent
ca24d0a56a
commit
0c73608ce5
36 changed files with 791 additions and 0 deletions
19
solutions/15/q1518/solution.go
Normal file
19
solutions/15/q1518/solution.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package q1518
|
||||
|
||||
func numWaterBottles(numBottles int, numExchange int) int {
|
||||
drink := 0
|
||||
empty := 0
|
||||
for {
|
||||
drink += numBottles
|
||||
empty += numBottles
|
||||
if empty < numExchange {
|
||||
break
|
||||
}
|
||||
|
||||
numBottles = empty / numExchange
|
||||
empty = empty % numExchange
|
||||
}
|
||||
return drink
|
||||
}
|
||||
|
||||
var _ = numWaterBottles
|
||||
13
solutions/15/q1523/solution.go
Normal file
13
solutions/15/q1523/solution.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package q1523
|
||||
|
||||
func countOdds(low int, high int) int {
|
||||
if low%2 == 1 {
|
||||
low -= 1
|
||||
}
|
||||
if high%2 == 1 {
|
||||
return (high-low)/2 + 1
|
||||
}
|
||||
return (high - low) / 2
|
||||
}
|
||||
|
||||
var _ = countOdds
|
||||
Loading…
Add table
Add a link
Reference in a new issue