Update 375. Guess Number Higher or Lower II.md

This commit is contained in:
ShusenTang 2020-08-24 22:27:16 +08:00 committed by GitHub
parent 40a5e8fdfb
commit d56d9a7462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {