We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7f040fc commit faebd88Copy full SHA for faebd88
README.md
@@ -5509,6 +5509,19 @@ class Solution:
5509
```
5510
- 时间复杂度:O(N),每次递归访问一个节点,总共N个节点
5511
- 空间复杂度: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, 借此方法可以缩减计算量
5525
5526
# 常用技巧总结
5527
- set 中的 in 操作时间复杂度为 O(1)
@@ -5532,6 +5545,7 @@ class Solution:
5532
5545
- 遍历 set 时,输出是无序的,输出顺序可能随着计算机环境而改变
5533
5546
- `[True, False, 0].index(0)` 输出为 1,因为 False == 0 为真,但 False is 0 为假
5534
5547
- `/` 为浮点数除法,`//` 为整数除法。`eg. 8 / 2.5 = 3.2, 8 // 2.5 = 3.0`,注意 `//` 的结果不一定为整数型
5548
+- 使用记忆化技术时,字典在多个 case 之间共享,应该考虑不同 case 的 key 是否相互影响
5535
5549
5536
5550
# 解法汇总贡献者
5537
5551
注:此处贡献名单仅代表汇总搜集贡献,不代表全部原创,欢迎所有更短的解法🤓
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments