{"id":7514,"date":"2026-07-27T22:50:44","date_gmt":"2026-07-27T14:50:44","guid":{"rendered":"https:\/\/i007.cc\/wordpress\/?p=7514"},"modified":"2026-07-27T22:50:44","modified_gmt":"2026-07-27T14:50:44","slug":"%e7%94%a8c%e8%ae%b2%e8%ae%b2%e4%ba%8c%e5%88%86%e6%9f%a5%e6%89%be%e6%89%be%e7%bc%ba%e5%a4%b1%e5%85%83%e7%b4%a0%e7%9a%84%e6%9c%80%e4%bd%b3%e6%80%9d%e8%b7%af","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/7514","title":{"rendered":"\u7528C++\u8bb2\u8bb2\u4e8c\u5206\u67e5\u627e\u627e\u7f3a\u5931\u5143\u7d20\u7684\u6700\u4f73\u601d\u8def"},"content":{"rendered":"<div data-rs-index=\"4\" data-index=\"4\">\n<div tabindex=\"0\" role=\"article\" aria-setsize=\"6\" aria-posinset=\"5\" aria-label=\"Message 5 of 6\">\n<div data-test-render-count=\"2\">\n<div class=\"mb-1 mt-[var(--msg-gap,1.5rem)] group group\/message-row\">\n<div class=\"flex flex-col items-end gap-1\">\n<div class=\"group relative inline-flex gap-2 bg-bg-300 dark:[[data-darker-default]_&amp;]:bg-bg-000 rounded-xl pl-2.5 py-[var(--msg-bubble-py,0.625rem)] break-words text-text-100 transition-all max-w-[75ch] flex-col !px-[var(--msg-bubble-px,1rem)] max-w-[85%]\" data-user-message-bubble=\"true\">\n<div class=\"flex flex-row gap-2 relative\">\n<div class=\"flex-1\">\n<div class=\"font-large !font-user-message py-0.5 grid grid-cols-1 gap-2 relative [&amp;_ul]:!space-y-0 [&amp;_ol]:!space-y-0 [&amp;_ul]:pl-8 [&amp;_ol]:pl-8\" data-testid=\"user-message\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"flex justify-start opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 pointer-coarse:opacity-100 transition-opacity duration-150\" data-message-action-bar=\"\">\n<div class=\"text-text-300\">\u8fd9\u9053\u9898\u7684\u7ecf\u5178\u573a\u666f\u662f\uff1a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6709\u5e8f\u6570\u7ec4\uff0c\u672c\u6765\u5e94\u8be5\u5305\u542b\u4e00\u6bb5\u8fde\u7eed\u6574\u6570\uff08\u6bd4\u5982 1 \u5230 n+1\uff0c\u6216\u8005 0 \u5230 n\uff09\uff0c\u4f46\u7f3a\u4e86\u4e00\u4e2a\uff0c\u8ba9\u4f60\u5728 O(log n) \u65f6\u95f4\u5185\u627e\u51fa\u7f3a\u7684\u662f\u54ea\u4e2a\u3002\u56e0\u4e3a\u6570\u7ec4\u6709\u5e8f\uff0c\u624d\u80fd\u7528\u4e8c\u5206\u67e5\u627e\uff0c\u601d\u8def\u7684\u5173\u952e\u662f\u627e\u4e00\u4e2a\u300cindex \u548c value \u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\u300d\uff0c\u901a\u8fc7\u8fd9\u4e2a\u6620\u5c04\u5173\u7cfb\u5224\u65ad\u7f3a\u5931\u70b9\u5728\u5de6\u8fb9\u8fd8\u662f\u53f3\u8fb9\u3002<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div data-rs-index=\"5\" data-index=\"5\" data-last-message=\"true\">\n<div tabindex=\"-1\" role=\"article\" aria-setsize=\"6\" aria-posinset=\"6\" aria-label=\"Message 6 of 6\">\n<div data-test-render-count=\"1\">\n<div class=\"group group\/message-row\">\n<div class=\"group relative relative pb-[var(--msg-assistant-pb,0.75rem)]\" data-is-streaming=\"false\">\n<div class=\"font-claude-response relative leading-[1.65rem] [&amp;_pre&gt;div]:bg-bg-000\/50 [&amp;_pre&gt;div]:border-0.5 [&amp;_pre&gt;div]:border-border-400 [&amp;_.ignore-pre-bg&gt;div]:bg-transparent [&amp;_.standard-markdown_:is(p,blockquote,h1,h2,h3,h4,h5,h6)]:pl-2 [&amp;_.standard-markdown_:is(p,blockquote,ul,ol,h1,h2,h3,h4,h5,h6)]:pr-8 [&amp;_.progressive-markdown_:is(p,blockquote,h1,h2,h3,h4,h5,h6)]:pl-2 [&amp;_.progressive-markdown_:is(p,blockquote,ul,ol,h1,h2,h3,h4,h5,h6)]:pr-8\">\n<div class=\"standard-markdown grid-cols-1 grid [&amp;_&gt;_*]:min-w-0 gap-3 [&amp;_&gt;_*:last-child]:mb-0 print:block print:[&amp;_&gt;_*_+_*]:mt-3 standard-markdown\">\n<p class=\"font-claude-response-body break-words whitespace-normal\" dir=\"ltr\">\u4ee5\u6700\u5e38\u89c1\u7684\u4e00\u79cd\u4e3a\u4f8b\uff1a\u6570\u7ec4 nums \u957f\u5ea6\u4e3a n\uff0c\u672c\u5e94\u662f\u4ece nums[0] \u5f00\u59cb\u7684\u8fde\u7eed\u6574\u6570\uff0c\u5373\u7406\u8bba\u4e0a nums[i] \u5e94\u8be5\u7b49\u4e8e nums[0] + i\u3002\u5982\u679c\u6ca1\u6709\u7f3a\u5931\uff0c\u4efb\u610f\u4f4d\u7f6e\u90fd\u6ee1\u8db3\u8fd9\u4e2a\u7b49\u5f0f\uff1b\u4e00\u65e6\u67d0\u4e2a\u4f4d\u7f6e\u5f00\u59cb\u51fa\u73b0 nums[i] &gt; nums[0] + i\uff0c\u8bf4\u660e\u7f3a\u5931\u7684\u5143\u7d20\u51fa\u73b0\u5728\u8fd9\u4e2a\u4f4d\u7f6e\u4e4b\u524d\uff08\u6216\u5c31\u662f\u8fd9\u4e2a\u4f4d\u7f6e\uff09\u3002\u4e8e\u662f\u53ef\u4ee5\u4e8c\u5206\uff1a\u6bcf\u6b21\u770b mid \u4f4d\u7f6e\u662f\u5426\u8fd8\u6ee1\u8db3 nums[mid] == nums[0] + mid\uff0c\u6ee1\u8db3\u8bf4\u660e\u7f3a\u7684\u6570\u5728\u53f3\u534a\u8fb9\uff0c\u4e0d\u6ee1\u8db3\u8bf4\u660e\u7f3a\u7684\u6570\u5728\u5de6\u534a\u8fb9\u6216\u5c31\u662f\u5f53\u524d\u4f4d\u7f6e\uff0c\u6536\u7f29\u533a\u95f4\u76f4\u5230\u5b9a\u4f4d\u5230\u7b2c\u4e00\u4e2a\u4e0d\u6ee1\u8db3\u7b49\u5f0f\u7684\u4f4d\u7f6e\u3002<\/p>\n<div class=\"relative group\/copy bg-bg-000\/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100\" tabindex=\"0\" role=\"group\" aria-label=\"cpp code\">\n<div class=\"sticky opacity-0 group-hover\/copy:opacity-100 group-focus-within\/copy:opacity-100 top-2 py-2 h-12 w-0 float-right\">\n<div class=\"absolute right-0 h-8 px-2 items-center inline-flex z-10\"><\/div>\n<\/div>\n<div class=\"text-text-500 font-small p-3.5 pb-0\">cpp<\/div>\n<div class=\"overflow-x-auto\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Solution {\r\npublic:\r\n    int findMissing(vector&lt;int&gt;&amp; nums) {\r\n        int left = 0, right = (int)nums.size() - 1;\r\n        int base = nums[0]; \/\/ \u7406\u8bba\u4e0a\u7b2c 0 \u4f4d\u5e94\u8be5\u662f\u7684\u503c\r\n\r\n        while (left &lt; right) {\r\n            int mid = left + (right - left) \/ 2;\r\n            if (nums[mid] == base + mid) {\r\n                \/\/ \u5de6\u534a\u8fb9\u5b8c\u597d\uff0c\u7f3a\u5931\u70b9\u5728\u53f3\u8fb9\r\n                left = mid + 1;\r\n            } else {\r\n                \/\/ \u5f53\u524d\u4f4d\u7f6e\u5df2\u7ecf\u9519\u4f4d\uff0c\u7f3a\u5931\u70b9\u5728\u8fd9\u91cc\u6216\u66f4\u5de6\u8fb9\r\n                right = mid;\r\n            }\r\n        }\r\n\r\n        \/\/ \u5faa\u73af\u7ed3\u675f\u65f6 left == right\uff0c\u6307\u5411\u7b2c\u4e00\u4e2a\u9519\u4f4d\u7684\u4f4d\u7f6e\r\n        return base + left;\r\n    }\r\n};<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<p class=\"font-claude-response-body break-words whitespace-normal\" dir=\"ltr\">\u8fd9\u4e2a\u5199\u6cd5\u7684\u5173\u952e\u5728\u4e8e\u4e8c\u5206\u7684\u5224\u65ad\u6761\u4ef6\u4e0d\u662f\u76f4\u63a5\u6bd4\u8f83 nums[mid] \u548c\u76ee\u6807\u503c\uff0c\u800c\u662f\u6bd4\u8f83\u300c\u5b9e\u9645\u503c\u300d\u548c\u300c\u671f\u671b\u503c\u300d\u7684\u5173\u7cfb\uff0c\u8fd9\u662f\u6570\u7ec4\u7c7b\u4e8c\u5206\u548c\u666e\u901a\u67e5\u627e\u7c7b\u4e8c\u5206\u6700\u5927\u7684\u533a\u522b\uff1a\u666e\u901a\u4e8c\u5206\u662f\u5728\u6570\u503c\u7a7a\u95f4\u91cc\u627e\u76ee\u6807\uff0c\u8fd9\u91cc\u662f\u5728\u4e0b\u6807\u7a7a\u95f4\u91cc\u901a\u8fc7\u4e00\u4e2a\u5355\u8c03\u7684\u8c13\u8bcd\uff08\u9519\u4f4d\u4e0e\u5426\uff09\u6765\u6536\u7f29\u8fb9\u754c\uff0c\u672c\u8d28\u4e0a\u662f\u4e8c\u5206\u67e5\u627e\u91cc\u300c\u627e\u7b2c\u4e00\u4e2a\u6ee1\u8db3\u67d0\u6761\u4ef6\u7684\u4f4d\u7f6e\u300d\u8fd9\u4e00\u7c7b\u6a21\u677f\u7684\u5e94\u7528\u3002<\/p>\n<p class=\"font-claude-response-body break-words whitespace-normal\" dir=\"ltr\">\u590d\u6742\u5ea6\u4e0a\u65f6\u95f4\u662f O(log n)\uff0c\u7a7a\u95f4 O(1)\uff0c\u6bd4\u904d\u5386\u4e00\u904d\u6570\u7ec4\u505a\u5dee\u503c\u5224\u65ad\uff08O(n)\uff09\u6216\u8005\u7528\u6c42\u548c\/\u5f02\u6216\u7684\u65b9\u6cd5\uff08\u540c\u6837 O(n)\uff0c\u867d\u7136\u66f4\u7701\u5fc3\u4f46\u6ca1\u5229\u7528\u4e0a\u6570\u7ec4\u6709\u5e8f\u8fd9\u4e2a\u6761\u4ef6\uff09\u8981\u5feb\u3002<\/p>\n<p class=\"font-claude-response-body break-words whitespace-normal\" dir=\"ltr\">\u51e0\u4e2a\u9700\u8981\u6ce8\u610f\u7684\u8fb9\u754c\u60c5\u51b5\uff1a\u5982\u679c\u7f3a\u5931\u7684\u5143\u7d20\u6b63\u597d\u662f\u6570\u7ec4\u672b\u5c3e\u4e4b\u540e\u90a3\u4e2a\u6570\uff08\u6bd4\u5982 1 \u5230 n+1 \u7f3a\u4e86 n+1\uff09\uff0c\u4e0a\u9762\u8fd9\u4e2a\u5199\u6cd5\u6700\u7ec8 left \u4f1a\u7b49\u4e8e nums.size()-1 \u4f46 nums[left] \u4ecd\u7136\u7b49\u4e8e base+left\uff08\u56e0\u4e3a\u6570\u7ec4\u91cc\u6ca1\u6709\u9519\u4f4d\u70b9\uff09\uff0c\u8fd9\u65f6\u5019\u8981\u5728\u5faa\u73af\u5916\u5355\u72ec\u5224\u65ad\uff0c\u8fd4\u56de nums[right] + 1 \u6216\u8005 base + nums.size()\uff0c\u5177\u4f53\u5199\u6cd5\u8981\u770b\u9898\u76ee\u91cc\u6570\u7ec4\u7684\u8303\u56f4\u5b9a\u4e49\u662f\u5de6\u95ed\u53f3\u5f00\u8fd8\u662f\u5de6\u95ed\u53f3\u95ed\uff0c\u5199\u4ee3\u7801\u524d\u4e00\u5b9a\u8981\u5148\u628a\u300c\u7f3a\u5931\u53ef\u80fd\u53d1\u751f\u5728\u6570\u7ec4\u672b\u5c3e\u4e4b\u540e\u300d\u8fd9\u4e2a\u8fb9\u754c\u60c5\u51b5\u60f3\u6e05\u695a\uff0c\u5426\u5219\u5bb9\u6613\u6f0f\u6389\u8fd9\u4e00\u79cd\u60c5\u51b5\u5bfc\u81f4\u8fd4\u56de\u9519\u8bef\u7b54\u6848\u3002<\/p>\n<p class=\"font-claude-response-body break-words whitespace-normal\" dir=\"ltr\">\u5982\u679c\u6570\u7ec4\u4e0d\u662f\u4ece\u56fa\u5b9a base \u5f00\u59cb\uff0c\u800c\u662f\u50cf 1 \u5230 n \u5c11\u4e00\u4e2a\u6570\u53d8\u6210\u957f\u5ea6 n-1 \u7684\u573a\u666f\uff0c\u5224\u65ad\u6761\u4ef6\u8981\u76f8\u5e94\u6539\u6210 nums[mid] &#8211; mid \u662f\u5426\u7b49\u4e8e\u67d0\u4e2a\u4e0d\u53d8\u91cf\uff08\u6bd4\u5982\u6070\u597d\u7b49 1\uff09\uff0c\u539f\u7406\u662f\u4e00\u6837\u7684\uff0c\u53ea\u662f\u671f\u671b\u503c\u7684\u8868\u8fbe\u5f0f\u4e0d\u540c\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u9053\u9898\u7684\u7ecf\u5178\u573a\u666f\u662f\uff1a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6709<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[24],"tags":[],"class_list":["post-7514","post","type-post","status-publish","format-standard","hentry","category-value_docs"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/7514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=7514"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/7514\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=7514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=7514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=7514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}