my solution


  • 0
    C
    public class Solution {
        public int mySqrt(int x) {
            if(x<=0){
                    return x;
                }
                int l = 1;
                int h = x;
                while(l<=h){
                    int mid = l+(h-l)/2;
                    if(mid>x/mid){
                        h = mid-1;
                    }else{
                        l = mid+1;
                    }
                }
                return h;
        }
    }
    

Log in to reply
 

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