# Pow(x, n)

<p>实现 <a href="https://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(<em>x</em>, <em>n</em>)</a> ，即计算 x 的 n 次幂函数（即，x<sup><span style="font-size:10.8333px">n</span></sup>）。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>x = 2.00000, n = 10<strong><br />输出：</strong>1024.00000</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>x = 2.10000, n = 3<strong><br />输出：</strong>9.26100</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>x = 2.00000, n = -2<strong><br />输出：</strong>0.25000<strong><br />解释：</strong>2<sup>-2</sup> = 1/2<sup>2</sup> = 1/4 = 0.25</pre><p> </p><p><strong>提示：</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>

以下程序实现了这一功能，请你填补空白处内容：

```cpp
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	double myPow(double x, int n)
	{
		if (n == INT_MIN)
		{
			double t = dfs(x, -(n / 2));
			return 1 / t * 1 / t;
		}
		else
		{
			___________________;
		}
	}
private:
	double dfs(double x, int n)
	{
		if (n == 0)
		{
			return 1;
		}
		else if (n == 1)
		{
			return x;
		}
		else
		{
			double t = dfs(x, n / 2);
			return (n % 2) ? (x * t * t) : (t * t);
		}
	}
};
```

## template

```cpp
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	double myPow(double x, int n)
	{
		if (n == INT_MIN)
		{
			double t = dfs(x, -(n / 2));
			return 1 / t * 1 / t;
		}
		else
		{
			return n < 0 ? 1 / dfs(x, -n) : dfs(x, n);
		}
	}
private:
	double dfs(double x, int n)
	{
		if (n == 0)
		{
			return 1;
		}
		else if (n == 1)
		{
			return x;
		}
		else
		{
			double t = dfs(x, n / 2);
			return (n % 2) ? (x * t * t) : (t * t);
		}
	}
};
```

## 答案

```cpp
return n < 0 ? 1 / dfs(x, -n) : dfs(x, n);
```

## 选项

### A

```cpp
return n < 0 ? 1 / dfs(x, n) : dfs(x, -n);
```

### B

```cpp
return n < 0 ? dfs(x, -n) : 1 / dfs(x, n);
```

### C

```cpp
return n < 0 ? dfs(x, n) : 1 / dfs(x, -n);
```