# Leetcode 69 - Sqrt

Given a non-negative integer x, compute and return the square root of x.

Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.

Example 1:

Example 2:

Constraints:

• 0 <= x <= 231 - 1

Thoughts: To use binary search, initialize left as 0 and right as Number.MAX_VALUE. Everytime we compare mid with x/mid in which mid is just left + (right-left)/2. We have to write it in this form so it won’t overflow. Also, when we compare if mid^2 is bigger or smaller than x, we have to write it as mid vs x/mid.