Sqrt(x)
Easy
Binary Search
Math
Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator.
Examples:
Input:
4Output:
2Explanation: The square root of 4 is 2.
Input:
8Output:
2Explanation: The square root of 8 is 2.828..., and since we round it down to the nearest integer, the answer is 2.
Constraints:
- 0 ≤ x ≤ 2³¹ - 1
Code Editor
Loading advanced editor...
Console Output
Ready to execute
Click "Run Code" to see your output here