<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=69.Sqrt%28x%29</id>
	<title>69.Sqrt(x) - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=69.Sqrt%28x%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=69.Sqrt(x)&amp;action=history"/>
	<updated>2026-06-02T18:56:46Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=69.Sqrt(x)&amp;diff=4149&amp;oldid=prev</id>
		<title>Riguz：​创建页面，内容为“=Description= {{LeetCode |id=sqrtx |no=69 |difficulty=Easy |category=Math |collection=Top 150 |title=Sqrt(x) |summary=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++ or x ** 0.5 in python.    Example 1:  &lt;syntaxhighlight lang=&quot;bash&quot;&gt; Input: x = 4 Output:…”</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=69.Sqrt(x)&amp;diff=4149&amp;oldid=prev"/>
		<updated>2024-02-29T14:02:09Z</updated>

		<summary type="html">&lt;p&gt;创建页面，内容为“=Description= {{LeetCode |id=sqrtx |no=69 |difficulty=Easy |category=Math |collection=Top 150 |title=Sqrt(x) |summary=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++ or x ** 0.5 in python.    Example 1:  &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt; Input: x = 4 Output:…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Description=&lt;br /&gt;
{{LeetCode&lt;br /&gt;
|id=sqrtx&lt;br /&gt;
|no=69&lt;br /&gt;
|difficulty=Easy&lt;br /&gt;
|category=Math&lt;br /&gt;
|collection=Top 150&lt;br /&gt;
|title=Sqrt(x)&lt;br /&gt;
|summary=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.}}&lt;br /&gt;
&lt;br /&gt;
You must not use any built-in exponent function or operator.&lt;br /&gt;
&lt;br /&gt;
For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Example 1:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Input: x = 4&lt;br /&gt;
Output: 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Explanation: The square root of 4 is 2, so we return 2.&lt;br /&gt;
Example 2:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Input: x = 8&lt;br /&gt;
Output: 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Explanation: The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.&lt;br /&gt;
&lt;br /&gt;
===Binary search===&lt;br /&gt;
{{Submission|runtime=1ms|memory=40.82MB|rp=86.98|mp=40.25}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
class Solution {&lt;br /&gt;
    public int mySqrt(int x) {&lt;br /&gt;
        int l = 1, r = x;&lt;br /&gt;
        while(l &amp;lt;= r){&lt;br /&gt;
           int m = (r-l)/2 + l;&lt;br /&gt;
           if(m &amp;gt; x/m) r = m-1;&lt;br /&gt;
           else if(m &amp;lt; x/m) l = m+1;&lt;br /&gt;
           else return m;&lt;br /&gt;
        }&lt;br /&gt;
        return r;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Algorithm]]&lt;br /&gt;
[[Category:Math]]&lt;br /&gt;
[[Category:LeetCode]]&lt;/div&gt;</summary>
		<author><name>Riguz</name></author>
	</entry>
</feed>