Package g0001_0100.s0069_sqrtx
Class Solution
java.lang.Object
g0001_0100.s0069_sqrtx.Solution
69 - Sqrt(x).<p>Easy</p>
<p>Given a non-negative integer <code>x</code>, compute and return <em>the square root of</em> <code>x</code>.</p>
<p>Since the return type is an integer, the decimal digits are <strong>truncated</strong> , and only <strong>the integer part</strong> of the result is returned.</p>
<p><strong>Note:</strong> You are not allowed to use any built-in exponent function or operator, such as <code>pow(x, 0.5)</code> or <code>x ** 0.5</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> x = 4</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> x = 8</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The square root of 8 is 2.82842…, and since the decimal part is truncated, 2 is returned.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 <= x <= 2<sup>31</sup> - 1</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
mySqrt
public int mySqrt(int x)
-