Search
Given a non-negative integer, write a function to compute the square root using binary search. If the square root is not an integer, return the floor value.
x
i * i <= x
i
low = 1
high = x
mid = Math.floor((low + high) / 2)
mid * mid == x
mid
mid * mid < x
low
mid + 1
mid * mid > x
high
mid - 1
high = 8
mid = 4
high = 3
mid = 2
low = 3
mid = 3
high = 2