Python Binary Search


  • 0
    class Solution(object):
        def mySqrt(self, x):
            left, right = 0, x + 1
            while right - left > 1:
                mid = (left + right) >> 1
                if mid ** 2 <= x:
                    left = mid
                else:
                    right = mid 
            return left
    

Log in to reply
 

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