sqrtx

作者: DaiMorph | 来源:发表于2019-07-18 23:13 被阅读0次
class Solution {
public:
    int sqrt(int x) {
        int left=1,right=x/2;
        int res;
        if(x<2)return x;
        while(left<=right)
        {
            int mid=(right-left)/2+left;
            if(x/mid>mid)left=mid+1,res=mid;
            else if(x/mid<mid)right=mid-1;
            else return mid;
        }
        return res;
    }
};

相关文章

网友评论

      本文标题:sqrtx

      本文链接:https://www.haomeiwen.com/subject/vxbhlctx.html