add new solutions
This commit is contained in:
parent
9c2c959a9b
commit
9a10695e8c
29 changed files with 1074 additions and 2 deletions
25
solutions/0/q50/solution.go
Normal file
25
solutions/0/q50/solution.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package q50
|
||||
|
||||
func myPow(x float64, n int) float64 {
|
||||
neg := n < 0
|
||||
if neg {
|
||||
n = -n
|
||||
}
|
||||
|
||||
var ret float64 = 1
|
||||
for n > 0 {
|
||||
v, p := x, 1
|
||||
for p*2 < n {
|
||||
p *= 2
|
||||
v *= v
|
||||
}
|
||||
n -= p
|
||||
ret *= v
|
||||
}
|
||||
if neg {
|
||||
return 1 / ret
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
var _ = myPow
|
||||
Loading…
Add table
Add a link
Reference in a new issue