sqrt


  • 0
    A

    class Solution {
    public:

    int mySqrt(int x) {
    long mid;    
    int beg,end,save;
    beg=1;
    end=x;
    

    while(beg<=end)
    {
    mid=(beg+end)/2;
    if((mid*mid)<=x)
    {
    save=mid;
    beg=mid+1;
    }
    else
    end=mid-1;
    }
    return save;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.