← 返回 oracle 的题目列表Integer Square Root
类型:online_judge
Given a non-negative integer x, return the integer part of its square root, i.e. ⌊√x⌋.
The result must be a non-negative integer. Do not call built-in square-root functions or use an exponent operator to compute the square root.
Example 1:
Input: x = 4
Output: 2
Example 2:
Input: x = 8
Output: 2
Explanation: √8 ≈ 2.828, so its integer part is 2.
Constraints:
0 <= x <= 2^31 - 1
Follow-up: How would you compute the square root if the input can be a non-negative real number smaller than 1?
Example
Input
4
Output
2