{"id":3997,"date":"2023-11-02T09:41:00","date_gmt":"2023-11-02T01:41:00","guid":{"rendered":"https:\/\/white-night.club\/?p=3997"},"modified":"2024-04-02T18:26:51","modified_gmt":"2024-04-02T10:26:51","slug":"ad121","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/02\/ad121\/","title":{"rendered":"69.\u00a0x \u7684\u5e73\u65b9\u6839"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u975e\u8d1f\u6574\u6570&nbsp;<code>x<\/code>&nbsp;\uff0c\u8ba1\u7b97\u5e76\u8fd4\u56de&nbsp;<code>x<\/code>&nbsp;\u7684&nbsp;<strong>\u7b97\u672f\u5e73\u65b9\u6839<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u8fd4\u56de\u7c7b\u578b\u662f\u6574\u6570\uff0c\u7ed3\u679c\u53ea\u4fdd\u7559&nbsp;<strong>\u6574\u6570\u90e8\u5206&nbsp;<\/strong>\uff0c\u5c0f\u6570\u90e8\u5206\u5c06\u88ab&nbsp;<strong>\u820d\u53bb \u3002<\/strong><\/p>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u4e0d\u5141\u8bb8\u4f7f\u7528\u4efb\u4f55\u5185\u7f6e\u6307\u6570\u51fd\u6570\u548c\u7b97\u7b26\uff0c\u4f8b\u5982&nbsp;<code>pow(x, 0.5)<\/code>&nbsp;\u6216\u8005&nbsp;<code>x ** 0.5<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>x = 4\n<strong>\u8f93\u51fa\uff1a<\/strong>2\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>x = 8\n<strong>\u8f93\u51fa\uff1a<\/strong>2\n<strong>\u89e3\u91ca\uff1a<\/strong>8 \u7684\u7b97\u672f\u5e73\u65b9\u6839\u662f 2.82842..., \u7531\u4e8e\u8fd4\u56de\u7c7b\u578b\u662f\u6574\u6570\uff0c\u5c0f\u6570\u90e8\u5206\u5c06\u88ab\u820d\u53bb\u3002\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><code>0 &lt;= x &lt;= 2<sup>31<\/sup> - 1<\/code><\/li>\n<\/ul>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u4e8c\u5206\u67e5\u627e<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u597d\u4e45\u6ca1\u5199\u4e8c\u5206\u67e5\u627e\u7684\u9898\u4e86\uff0c\u8fd9\u6b21\u53c8\u8dea\u4e86\uff0c\u4ee4\u4eba\u611f\u6168\u3002\u8fc7\u51e0\u5929\u7b49\u5fd8\u7684\u5dee\u4e0d\u591a\u4e86\u518d\u7528go\u5199\u4e00\u904d\uff0c\u8fd9\u51e0\u5929\u5148\u91cd\u65b0\u590d\u4e60\u4e0b\u4e8c\u5206\u67e5\u627e\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">C++<\/span><span role=\"button\" tabindex=\"0\" data-code=\"class Solution {\npublic:\n    int mySqrt(int x) {\n        int left=0,right=x,ans=0;\n        while(left&lt;=right)\n        {\n            int mid=left+(right-left)\/2;\n            if((long long)mid*mid&lt;=x)\n            {\n                ans=mid;\n                left=mid+1;\n            }else{\n                right=mid-1;\n            }\n        }    \n        return ans;\n    }\n};\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">class<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Solution<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">mySqrt<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">x<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> left=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">,right=x,ans=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">while<\/span><span style=\"color: #D4D4D4\">(left&lt;=right)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> mid=left+(right-left)\/<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\">((<\/span><span style=\"color: #569CD6\">long<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">long<\/span><span style=\"color: #D4D4D4\">)mid*mid&lt;=x)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                ans=mid;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                left=mid+<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            }<\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                right=mid-<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        }    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> ans;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">};<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u4e8c\u5206\u67e5\u627e<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3997"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=3997"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3997\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}