Skip to content

Commit efaab32

Browse files
committed
up
1 parent b96bd27 commit efaab32

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

leetcode/50.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ n 是 32 位有符号整数,其数值范围是 [−231, 231 − 1] 。
5050

5151
### Solution1
5252

53-
暴力解法
53+
暴力解法(超时)
5454

5555
```java
5656
class Solution {
@@ -70,7 +70,34 @@ class Solution {
7070

7171
### Solution2
7272

73+
二分
7374

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)
74100

75101
# 题解
76102

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

Comments
 (0)