1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| // @Title: 数值的整数次方 (数值的整数次方 LCOF)
// @Author: 15816537946@163.com
// @Date: 2022-02-21 22:27:32
// @Runtime: 0 ms
// @Memory: 1.9 MB
func myPow(x float64, n int) float64 {
if n == 0 {
return 1
}
if n == 1 {
return x
}
if n <0 {
x = 1/x
n = -n
}
temp := myPow(x, n/2)
if n%2 == 0 {
return temp * temp
}
return x *temp * temp
}
|