We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b96bd27 commit efaab32Copy full SHA for efaab32
leetcode/50.md
@@ -50,7 +50,7 @@ n 是 32 位有符号整数,其数值范围是 [−231, 231 − 1] 。
50
51
### Solution1
52
53
-暴力解法
+暴力解法(超时)
54
55
```java
56
class Solution {
@@ -70,7 +70,34 @@ class Solution {
70
71
### Solution2
72
73
+二分
74
75
+```java
76
+class Solution {
77
+ public double myPow(double x, int n) {
78
+ if(x == 0) return 0;
79
+ long b = n;
80
+ double res = 1.0;
81
+ if(b < 0) {
82
+ x = 1 / x;
83
+ b = -b;
84
+ }
85
+ while(b > 0) {
86
+ if((b & 1) == 1) res *= x;
87
+ x *= x;
88
+ b >>= 1;
89
90
+ return res;
91
92
+}
93
+
94
+```
95
96
+##### 复杂度分析:
97
98
++ 时间复杂度 O(logn)
99
++ 空间复杂度 O(1)
100
101
# 题解
102
103
+https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/solution/mian-shi-ti-16-shu-zhi-de-zheng-shu-ci-fang-kuai-s/
0 commit comments