二分法
ChasingTheFreeWind
这个作者很懒,什么都没留下…
展开
-
leetcode 每日一题 69.x的平方根(二分+迭代)
思路 求平方根的方法主要有二分法和数学上的迭代法,迭代公式An+1 = (An+x/An)/2 二分法 注意细节 class Solution { public: int mySqrt(int x) { if(x<=1) return x; int le = 0; int ri = x/2+1; int mid = ri-(ri-le)/2; while(le+1<ri) .原创 2020-05-09 11:48:05 · 157 阅读 · 0 评论 -
leetcode每日一题 1095.山脉数组中查找目标值(三次二分)
三次二分解决问题,注意细节就好。 代码 /** * // This is the MountainArray's API interface. * // You should not implement it, or speculate about its implementation * class MountainArray { * public: * int get(...原创 2020-04-29 15:28:31 · 134 阅读 · 0 评论