#69

Sqrt(x)

pupil · 525 · lc easy +28 · verified · 41.5% accepted · 9,619 likes · top 22%

play →

Description

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.

Code

1
2
3