A 7-Line C# Solution


  • 0
    L
    public int MySqrt(int x) {
        int i = 1, j = x;
        while(i < j){
            int mid = (i + j) >> 1;
            if(x / mid < mid) j = mid;
            else i = mid + 1;
        }
        return x / i < i ? i - 1 : i;
    }

Log in to reply
 

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