leetcode-----69. x 的平方根

代码

class Solution {
public:
    int mySqrt(int x) {
        int l = 0, r = x;
        while (l < r) {
            int mid = (l + 1ll + r) / 2;
            if (mid <= x / mid) l = mid;
            else r = mid - 1; 
        }
        return l;
    }
};
posted @ 2020-07-11 10:03  景云ⁿ  阅读(72)  评论(0编辑  收藏  举报