We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b66ea1c commit ca404aaCopy full SHA for ca404aa
PowOfXN/pow_of_x_n.go
@@ -61,7 +61,7 @@ func myPow(x float64, n int) float64 {
61
}
62
63
64
-*/
+
65
66
67
@@ -91,3 +91,38 @@ func myPow(x float64, n int) float64 {
91
92
return ans
93
94
+*/
95
96
+// Fastest Bitwise
97
98
+func power(x float64, n int) float64 {
99
+ if n == 0 {
100
+ return 1
101
+ }
102
103
+ if n%2 == 0 {
104
+ return power(x*x, n/2)
105
106
107
+ return x * power(x, n-1)
108
+}
109
110
+func myPow(x float64, n int) float64 {
111
112
113
114
115
+ var l int
116
+ if n < 0 {
117
+ l = -n
118
+ } else {
119
+ l = n
120
121
122
+ ans := power(x, l)
123
124
+ return 1 / ans
125
126
127
+ return ans
128
0 commit comments