{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "30e3315d78704fd089eb9bccc0680b27",
  "keywords": "数学,二分查找",
  "title": "x 的平方根",
  "desc": [
    {
      "content": "\n<p>实现&nbsp;<code>int sqrt(int x)</code>&nbsp;函数。</p>\n<p>计算并返回&nbsp;<em>x</em>&nbsp;的平方根，其中&nbsp;<em>x </em>是非负整数。</p>\n<p>由于返回类型是整数，结果只保留整数的部分，小数部分将被舍去。</p>\n<p><strong>示例 1:</strong></p>\n<pre><strong>输入:</strong> 4<strong><br />输出:</strong> 2</pre>\n<p><strong>示例 2:</strong></p>\n<pre><strong>输入:</strong> 8<strong><br />输出:</strong> 2<strong><br />说明:</strong> 8 的平方根是 2.82842..., 由于返回类型是整数，小数部分将被舍去。</pre>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution:\n\tdef mySqrt(self, x):\n\t\tif x == 0:\n\t\t\treturn 0\n\t\tif x < 4:\n\t\t\treturn 1\n\t\tres = 2 * self.mySqrt(x / 4)\n\t\tif (res + 1) * (res + 1) <= x and (res + 1) * (res + 1) >= 0:\n\t\t\treturn res + 1\n\t\treturn  res\n# %%\ns = Solution()\nprint(s.mySqrt(4))",
    "language": "python"
  },
  "node_id": "dailycode-d5d81e058c794c00ad9824c7649d4168",
  "license": "csdn.net",
  "created_at": 1637894161,
  "topic_link": "https://bbs.csdn.net/topics/600470124"
}