mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
Update 375. Guess Number Higher or Lower II.md
This commit is contained in:
parent
40a5e8fdfb
commit
d56d9a7462
@ -22,9 +22,11 @@ for all k in [i+1, j-1]:
|
||||
|
||||
时间复杂度O(n^3), 空间复杂度O(n^2)。
|
||||
|
||||
本题时间复杂度可优化至O(n^2),可参考[1](https://artofproblemsolving.com/community/c296841h1273742)和[2](https://leetcode.com/problems/guess-number-higher-or-lower-ii/discuss/84823/Java-O(n2)-DP-solution-with-clear-explanation)。
|
||||
本题时间复杂度可优化至O(n^2),可参考[1](https://artofproblemsolving.com/community/c296841h1273742)和[2](https://blog.csdn.net/Site1997/article/details/100168676)。
|
||||
亲测确实快一些,但是乍一看没怎么看懂,留个坑吧。
|
||||
|
||||
> 注意:此题很容易错误地认为二分就是最优,但其实不是。二分只能保证猜测次数最小,而不是最坏情况下花费的钱最少。例如n=5,若采用二分,那么最坏情况下花费是3+4=7;但是实际上应该是4+2=6。
|
||||
|
||||
# C++
|
||||
``` C++
|
||||
class Solution {
|
||||
|
Loading…
Reference in New Issue
Block a user