{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "096ba255d3f74daca6719e44801429dd",
  "keywords": "递归,数学",
  "title": "Pow(x, n)",
  "desc": [
    {
      "content": "\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>\t<li><code>-100.0 < x < 100.0</code></li>\t<li><code>-2<sup>31</sup> <= n <= 2<sup>31</sup>-1</code></li>\t<li><code>-10<sup>4</sup> <= x<sup>n</sup> <= 10<sup>4</sup></code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "public class Solution {\n\tpublic double myPow(double x, int n) {\n\t\tif (n < 0) {\n\n\t\t\treturn 1 / pow(x, -n);\n\t\t} else {\n\n\t\t\treturn pow(x, n);\n\t\t}\n\t}\n\n\tprivate double pow(double x, int n) {\n\n\t\tif (n == 0) {\n\t\t\treturn 1.0;\n\t\t}\n\t\tif (n == 1) {\n\t\t\treturn x;\n\t\t}\n\t\tdouble val = pow(x, n / 2);\n\n\t\tif (n % 2 == 0) {\n\t\t\treturn val * val;\n\t\t} else {\n\t\t\treturn val * val * x;\n\t\t}\n\t}\n}\n",
    "language": "java"
  },
  "node_id": "dailycode-aa14a10d3dbc4e2a983c7cffd4eca240",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600471013"
}