Compute the Floor of a Number's Square Root
Implement mySqrt
Given a non-negative integer
x, return the floor of its square root — the largest integer whose square doesn't exceed x — without using any built-in power or square-root function.
The candidate answers 0 through x split cleanly into "square ≤ x" and "square > x", in that order, which makes this a binary search over the answer itself rather than over an array.
Example 1:
Input: x = 8
Output: 2
Example 2:
Input: x = 4
Output: 2
Example 3:
Input: x = 0
Output: 0
+ 4 hidden test cases run on Submit.
Constraints:
- ●
0 ≤ x ≤ 2³¹ - 1
x =
8