1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/x 的平方根 (English) [sqrtx].html

32 lines
1005 B
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>Given a non-negative integer <code>x</code>, return <em>the square root of </em><code>x</code><em> rounded down to the nearest integer</em>. The returned integer should be <strong>non-negative</strong> as well.</p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<p>You <strong>must not use</strong> any built-in exponent function or operator.</p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<ul>
<li>For example, do not use <code>pow(x, 0.5)</code> in c++ or <code>x ** 0.5</code> in python.</li>
</ul>
2022-03-27 20:56:26 +08:00
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p><strong class="example">Example 1:</strong></p>
2022-03-27 20:56:26 +08:00
<pre>
<strong>Input:</strong> x = 4
<strong>Output:</strong> 2
2023-12-09 18:42:21 +08:00
<strong>Explanation:</strong> The square root of 4 is 2, so we return 2.
2022-03-27 20:56:26 +08:00
</pre>
2023-12-09 18:42:21 +08:00
<p><strong class="example">Example 2:</strong></p>
2022-03-27 20:56:26 +08:00
<pre>
<strong>Input:</strong> x = 8
<strong>Output:</strong> 2
2023-12-09 18:42:21 +08:00
<strong>Explanation:</strong> The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.
</pre>
2022-03-27 20:56:26 +08:00
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 &lt;= x &lt;= 2<sup>31</sup> - 1</code></li>
</ul>