Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit faebd88

Browse files
add 50
1 parent 7f040fc commit faebd88

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5509,6 +5509,19 @@ class Solution:
55095509
```
55105510
- 时间复杂度:O(N),每次递归访问一个节点,总共N个节点
55115511
- 空间复杂度:O(N),最糟糕的情况是树完全不平衡,递归开栈消耗 O(N) 空间
5512+
#### [50. Pow(x, n)](https://leetcode-cn.com/problems/powx-n/)
5513+
```python
5514+
class Solution:
5515+
def myPow(self, x: float, n: int) -> float:
5516+
if abs(n) <= 1:
5517+
return (1, x, 1/x)[n]
5518+
5519+
root = self.myPow(x, n // 2)
5520+
return (1, x)[n % 2] * root * root
5521+
```
5522+
- 时间复杂度:O(logN)
5523+
- 空间复杂度:O(logN)
5524+
- x^4 = x^2 ** x^2, x^5 = x^2 * x^2 * x, 借此方法可以缩减计算量
55125525

55135526
# 常用技巧总结
55145527
- set 中的 in 操作时间复杂度为 O(1)
@@ -5532,6 +5545,7 @@ class Solution:
55325545
- 遍历 set 时,输出是无序的,输出顺序可能随着计算机环境而改变
55335546
- `[True, False, 0].index(0)` 输出为 1,因为 False == 0 为真,但 False is 0 为假
55345547
- `/` 为浮点数除法,`//` 为整数除法。`eg. 8 / 2.5 = 3.2, 8 // 2.5 = 3.0`,注意 `//` 的结果不一定为整数型
5548+
- 使用记忆化技术时,字典在多个 case 之间共享,应该考虑不同 case 的 key 是否相互影响
55355549

55365550
# 解法汇总贡献者
55375551
注:此处贡献名单仅代表汇总搜集贡献,不代表全部原创,欢迎所有更短的解法🤓

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /