Easy

Quiz

#69 Sqrt(x)

APPROACH

Return the integer floor of the square root of non-negative integer x. Built-in exponent functions or operators such as pow(x, 0.5) or x ** 0.5 are not permitted.

Example 1:

Input: x = 4
Output: 2
Explanation: The square root of 4 is 2, so we return 2.

Example 2:

Input: x = 8
Output: 2
Explanation: The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.
1 of 4
1:00

What is the optimal approach for this problem?