mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			35 lines
		
	
	
		
			1001 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			1001 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定一个非负整数 <code>x</code> ,计算并返回 <code>x</code> 的平方根,即实现 <code>int sqrt(int x)</code> 函数。</p>
 | 
						|
 | 
						|
<p>正数的平方根有两个,只输出其中的正数平方根。</p>
 | 
						|
 | 
						|
<p>如果平方根不是整数,输出只保留整数的部分,小数部分将被舍去。</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
 | 
						|
<p><strong>示例 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>输入:</strong> x = 4
 | 
						|
<strong>输出:</strong> 2
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong>示例 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>输入:</strong> x = 8
 | 
						|
<strong>输出:</strong> 2
 | 
						|
<strong>解释:</strong> 8 的平方根是 2.82842...,由于小数部分将被舍去,所以返回 2
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
 | 
						|
<p><strong>提示:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><meta charset="UTF-8" /><code>0 <= x <= 2<sup>31</sup> - 1</code></li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
 | 
						|
<p><meta charset="UTF-8" />注意:本题与主站 69 题相同: <a href="https://leetcode-cn.com/problems/sqrtx/">https://leetcode-cn.com/problems/sqrtx/</a></p>
 |