Package g0001_0100.s0050_powx_n
Class Solution
java.lang.Object
g0001_0100.s0050_powx_n.Solution
50 - Pow(x, n).<p>Medium</p>
<p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_top">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> x = 2.00000, n = 10</p>
<p><strong>Output:</strong> 1024.00000</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> x = 2.10000, n = 3</p>
<p><strong>Output:</strong> 9.26100</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> x = 2.00000, n = -2</p>
<p><strong>Output:</strong> 0.25000</p>
<p><strong>Explanation:</strong> 2<sup>-2</sup> = 1/2<sup>2</sup> = 1/4 = 0.25</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>-100.0 < x < 100.0</code></li>
<li><code>-2<sup>31</sup> <= n <= 2<sup>31</sup>-1</code></li>
<li><code>-10<sup>4</sup> <= x<sup>n</sup> <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
myPow
public double myPow(double x, int n)
-