Python solution, 76ms


  • 2
    I
    class Solution:
        # @param x, an integer
        # @return an integer
        def sqrt(self, x):
            start=0
            end=x
            while start<=end:
                mid=(start+end)/2
                if mid*mid>x:
                    end=mid-1
                else:
                    if (mid+1)*(mid+1)>x:
                        return mid
                    else:
                        start=mid+1

Log in to reply
 

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