69. Sqrt(x)
Description
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.
- For example, do not use
pow(x, 0.5)
in c++ orx ** 0.5
in python.
Example 1:
1 | Input: x = 4 |
Example 2:
1 | Input: x = 8 |
Constraints:
0 <= x <= 2^31 - 1
Hints/Notes
- 2025/04/26 Q1
- binary search
- Leetcode solution
Solution
Language: C++
1 | class Solution { |