{"id":117,"date":"2025-10-03T01:03:52","date_gmt":"2025-10-02T17:03:52","guid":{"rendered":"https:\/\/yxzhangcoco.xyz\/?p=117"},"modified":"2025-10-04T00:27:50","modified_gmt":"2025-10-03T16:27:50","slug":"%e5%8f%8c%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"https:\/\/yxzhangcoco.xyz\/index.php\/2025\/10\/03\/%e5%8f%8c%e6%8c%87%e9%92%88\/","title":{"rendered":"\u53cc\u6307\u9488"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6700\u8fd1\u7cfb\u7edf\u5b66\u4e60\u4e86\u90e8\u5206\u53cc\u6307\u9488\u7b97\u6cd5\u7684\u6280\u5de7\uff0c\u5728\u6b64\u7cfb\u7edf\u603b\u7ed3\u4e00\u4e0b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\uff0c\u5f15\u8a00<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u53cc\u6307\u9488\u90e8\u5206\u7684\u9898\u76ee\u975e\u5e38\u591a\uff0c\u7075\u6d3b\u6027\u6bd4\u8f83\u9ad8\uff0c\u603b\u7ed3\u4e00\u4e9b\u975e\u5e38\u6709\u610f\u4e49\u3002\u540c\u65f6\u4e00\u7bc7\u535a\u5ba2\u663e\u7136\u96be\u4ee5\u56ca\u62ec\u6240\u6709\u9898\u578b\uff0c\u672c\u6b21\u603b\u7ed3\u4e3b\u8981\u805a\u7126\u76f8\u5411\u6307\u9488\u4e0e\u540c\u5411\u6307\u9488\uff0c\u540e\u7eed\u5c06\u6709\u66f4\u591a\u7684\u6307\u9488\u603b\u7ed3\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\uff0c\u76f8\u5411\u6307\u9488<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e0e\u56de\u6587\u5b57\u7b26\u4e32&#8211;\u540c\u6b65\u76f8\u5411\u6307\u9488<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e0e\u56de\u6587\u5b57\u7b26\u4e32\u662f\u8f83\u4e3a\u7b80\u5355\u4e0e\u7406\u89e3\u7684\u76f8\u5411\u6307\u9488\u7528\u6cd5\uff0c<strong>\u6838\u5fc3\u601d\u60f3\u5373\u4e3a\u4e00\u8005\u6307\u5934\uff0c\u4e00\u8005\u6307\u5c3e\uff0c\u540c\u6b65\u76f8\u5411\u79fb\u52a8\uff0c\u8fb9\u79fb\u52a8\u8fb9\u5224\u65ad\u5373\u53ef\u3002<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.1.1<a href=\"https:\/\/leetcode.cn\/problems\/reverse-string\/description\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/reverse-string\/description\/\">\u53cd\u8f6c\u5b57\u7b26\u6570\u7ec4<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\uff0c\u5176\u4f5c\u7528\u662f\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u53cd\u8f6c\u8fc7\u6765\u3002\u8f93\u5165\u5b57\u7b26\u4e32\u4ee5\u5b57\u7b26\u6570\u7ec4&nbsp;<code>s<\/code>&nbsp;\u7684\u5f62\u5f0f\u7ed9\u51fa\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8981\u7ed9\u53e6\u5916\u7684\u6570\u7ec4\u5206\u914d\u989d\u5916\u7684\u7a7a\u95f4\uff0c\u4f60\u5fc5\u987b\u539f\u5730\u4fee\u6539\u8f93\u5165\u6570\u7ec4\u3001\u4f7f\u7528 O(1) \u7684\u989d\u5916\u7a7a\u95f4\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = [\"h\",\"e\",\"l\",\"l\",\"o\"]\n<strong>\u8f93\u51fa\uff1a<\/strong>[\"o\",\"l\",\"l\",\"e\",\"h\"]\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = [\"H\",\"a\",\"n\",\"n\",\"a\",\"h\"]<br><strong>\u8f93\u51fa\uff1a<\/strong>[\"h\",\"a\",\"n\",\"n\",\"a\",\"H\"]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee3\u7801\u5982\u4e0b\uff0c\u53ef\u4ee5\u770b\u5230\u975e\u5e38\u7b80\u5355\uff0c\u8bbe\u7f6e\u4e00\u4e2a\u5934\u6307\u9488\u4e00\u4e2a\u5c3e\u6307\u9488\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def reverseString(self, s: List&#91;str]) -&gt; None:\n        \"\"\"\n        Do not return anything, modify s in-place instead.\n        \"\"\"\n        head=0\n        tail=len(s)-1\n        while head&lt;tail:\n            s&#91;head],s&#91;tail]=s&#91;tail],s&#91;head]\n            head+=1\n            tail-=1\n\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.1.2<a href=\"https:\/\/leetcode.cn\/problems\/flip-square-submatrix-vertically\/description\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/flip-square-submatrix-vertically\/description\/\">\u5782\u76f4\u7ffb\u8f6c\u5b50\u77e9\u9635<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a&nbsp;m x n&nbsp;\u7684\u6574\u6570\u77e9\u9635&nbsp;grid\uff0c\u4ee5\u53ca\u4e09\u4e2a\u6574\u6570&nbsp;<code>x<\/code>\u3001<code>y<\/code>&nbsp;\u548c&nbsp;<code>k<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u6570&nbsp;<code>x<\/code>&nbsp;\u548c&nbsp;<code>y<\/code>&nbsp;\u8868\u793a\u4e00\u4e2a&nbsp;\u6b63\u65b9\u5f62\u5b50\u77e9\u9635&nbsp;\u7684\u5de6\u4e0a\u89d2\u4e0b\u6807\uff0c\u6574\u6570&nbsp;k&nbsp;\u8868\u793a\u8be5\u6b63\u65b9\u5f62\u5b50\u77e9\u9635\u7684\u8fb9\u957f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u7684\u4efb\u52a1\u662f\u5782\u76f4\u7ffb\u8f6c\u5b50\u77e9\u9635\u7684\u884c\u987a\u5e8f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd4\u56de\u66f4\u65b0\u540e\u7684\u77e9\u9635\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/assets.leetcode.com\/uploads\/2025\/07\/20\/gridexmdrawio.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/assets.leetcode.com\/uploads\/2025\/07\/20\/gridexmdrawio.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>&nbsp;grid =&nbsp;[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], x = 1, y = 0, k = 3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u51fa\uff1a<\/strong>&nbsp;[[1,2,3,4],[13,14,15,8],[9,10,11,12],[5,6,7,16]]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u9898\u5176\u5b9e\u4e0e\u53cd\u8f6c\u5b57\u7b26\u4e32\u6ca1\u4ec0\u4e48\u533a\u522b\uff0c\u53ea\u662f\u5c06\u5934\u5c3e\u6307\u9488\u6362\u6210\u4e86\u4e0a\u4e0b\u6307\u9488\u9010\u4e00\u4ea4\u6362\u884c\u5143\u7d20\u5373\u53ef\u3002\u540c\u65f6\u6d89\u53ca\u5230\u6279\u91cf\u4ea4\u6362\u5143\u7d20\uff0c<strong>\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528python\u5217\u8868\u91cc\u7684\u5207\u7247\u8d4b\u503c\u6765\u8fdb\u884c\u6279\u91cf\u53cd\u8f6c\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u5f97\u4ee3\u7801\u975e\u5e38\u7b80\u6d01\u4e14\u6613\u61c2\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def reverseSubmatrix(self, grid: List&#91;List&#91;int]], x: int, y: int, k: int) -&gt; List&#91;List&#91;int]]:\n        head=x\n        tail=x+k-1\n        while head&lt;tail:\n            grid&#91;head]&#91;y:y+k],grid&#91;tail]&#91;y:y+k]=grid&#91;tail]&#91;y:y+k],grid&#91;head]&#91;y:y+k]\n            head+=1\n            tail-=1\n        return grid\n\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.1.3<a href=\"https:\/\/leetcode.cn\/problems\/reverse-vowels-of-a-string\/description\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/reverse-vowels-of-a-string\/description\/\">\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u5143\u97f3\u5b57\u6bcd<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>&nbsp;\uff0c\u4ec5\u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5143\u97f3\u5b57\u6bcd\uff0c\u5e76\u8fd4\u56de\u7ed3\u679c\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5143\u97f3\u5b57\u6bcd\u5305\u62ec&nbsp;<code>'a'<\/code>\u3001<code>'e'<\/code>\u3001<code>'i'<\/code>\u3001<code>'o'<\/code>\u3001<code>'u'<\/code>\uff0c\u4e14\u53ef\u80fd\u4ee5\u5927\u5c0f\u5199\u4e24\u79cd\u5f62\u5f0f\u51fa\u73b0\u4e0d\u6b62\u4e00\u6b21\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>s = &#8220;IceCreAm&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u51fa\uff1a<\/strong>&#8220;AceCreIm&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>s<\/code>&nbsp;\u4e2d\u7684\u5143\u97f3\u662f&nbsp;<code>['I', 'e', 'e', 'A']<\/code>\u3002\u53cd\u8f6c\u8fd9\u4e9b\u5143\u97f3\uff0c<code>s<\/code>&nbsp;\u53d8\u4e3a&nbsp;&#8220;AceCreIm&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff0c\u5728python\uff0cjava\u4e2d\u5b57\u7b26\u4e32\u5c5e\u4e8e\u4e0d\u53ef\u53d8\u91cf\uff0c\u4e0d\u53ef\u4ee5\u76f4\u63a5\u50cf\u6570\u7ec4\u4e00\u6837\u9996\u5c3e\u4ea4\u6362\uff0c\u9700\u8981<strong>\u5148\u8f6c\u6362\u4e3a\u6570\u7ec4\u7136\u540e\u518d\u8fdb\u884c\u64cd\u4f5c<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u6cd5\u4e00\uff1a\u5faa\u73af\u5d4c\u5957<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def reverseVowels(self, s: str) -&gt; str:\n        head=0\n        tail=len(s)-1\n        temp=list(s)\n        while head&lt;tail:\n            while head&lt;len(s) and temp&#91;head] not in 'aeiouAEIOU':\n                head+=1\n            while tail&gt;=0 and s&#91;tail] not in 'aeiouAEIOU':\n                tail-=1\n            if head&gt;=tail:\n                break\n            temp&#91;head],temp&#91;tail]=temp&#91;tail],temp&#91;head]\n            head+=1\n            tail-=1\n        return \"\".join(temp)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u6cd5\u4e8c\uff1aif-else\u5224\u65ad<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def reverseVowels(self, s: str) -&gt; str:\n        head=0\n        tail=len(s)-1\n        temp=list(s)\n        while head&lt;tail:\n            if s&#91;head] not in 'aeiouAEIOU':\n                head+=1\n            elif s&#91;tail] not in 'aeiouAEIOU':\n                tail-=1\n            else:\n                temp&#91;head],temp&#91;tail]=temp&#91;tail],temp&#91;head]\n                head+=1\n                tail-=1\n        return \"\".join(temp)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8ff0\u4e24\u79cd\u5199\u6cd5\u90fd\u6bd4\u8f83\u76f4\u89c2\uff0c\u6027\u80fd\u4e5f\u51e0\u4e4e\u4e00\u76f4\uff0c\u7b2c\u4e8c\u79cd\u5199\u6cd5\u6bd4\u7b2c\u4e00\u79cd\u7a0d\u5fae\u6162\u4e00\u70b9\uff0c<strong>\u4e2a\u4eba\u6bd4\u8f83\u63a8\u8350\u7b2c\u4e8c\u79cd\uff0c\u56e0\u4e3a\u4e0d\u9700\u8981\u50cf\u7b2c\u4e00\u79cd\u90a3\u6837\u52a0\u4e09\u4e2a\u6761\u4ef6\u907f\u514d\u6307\u9488\u8d70\u8fc7\u5934\u3002<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.1.3<a href=\"https:\/\/leetcode.cn\/problems\/valid-palindrome\/description\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/valid-palindrome\/description\/\">\u9a8c\u8bc1<\/a><a href=\"https:\/\/leetcode.cn\/problems\/valid-palindrome\/description\/\">\u56de\u6587\u4e32<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u5728\u5c06\u6240\u6709\u5927\u5199\u5b57\u7b26\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u7b26\u3001\u5e76\u79fb\u9664\u6240\u6709\u975e\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u4e4b\u540e\uff0c\u77ed\u8bed\u6b63\u7740\u8bfb\u548c\u53cd\u7740\u8bfb\u90fd\u4e00\u6837\u3002\u5219\u53ef\u4ee5\u8ba4\u4e3a\u8be5\u77ed\u8bed\u662f\u4e00\u4e2a&nbsp;<strong>\u56de\u6587\u4e32<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u6bcd\u548c\u6570\u5b57\u90fd\u5c5e\u4e8e\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>\uff0c\u5982\u679c\u5b83\u662f&nbsp;<strong>\u56de\u6587\u4e32<\/strong>&nbsp;\uff0c\u8fd4\u56de&nbsp;true<em>&nbsp;<\/em>\uff1b\u5426\u5219\uff0c\u8fd4\u56de<em>&nbsp;<\/em>false<em>&nbsp;<\/em>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165:<\/strong> s = \"A man, a plan, a canal: Panama\"<br><strong>\u8f93\u51fa\uff1a<\/strong>true<br><strong>\u89e3\u91ca\uff1a<\/strong>\"amanaplanacanalpanama\" \u662f\u56de\u6587\u4e32\u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u9898\u9700\u8981\u6709\u4e00\u4e2a\u524d\u7f6e\u5904\u7406\uff0c\u5148\u5229\u7528\u5feb\u6162\u6307\u9488\u5c06\u542b\u6709\u975e\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u7eaf\u6570\u5b57\u5b57\u6bcd\u4e32\uff08\u540e\u9762\u540c\u5411\u6307\u9488\u91cc\u4f1a\u8bb2\u5230\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def isPalindrome(self, s: str) -&gt; bool:\n        res=\"\"\n        fast=0\n        while fast&lt;len(s):\n            if s&#91;fast].isalnum():\n                res+=s&#91;fast].lower()\n            fast+=1\n        head,tail=0,len(res)-1\n        while head&lt;tail:\n            if res&#91;head]!=res&#91;tail]:\n                return False\n            head+=1\n            tail-=1\n        return True<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u800c\uff0c\u8fd9\u6837\u5199\uff0c\u9996\u5148\u7a7a\u95f4\u590d\u6742\u5ea6\u4f1a\u53d8\u6210O\uff08n\uff09,\u65f6\u95f4\u590d\u6742\u5ea6\u8fd8\u4f1a\u53d8\u6210O(2*N)\uff0c\u8fd9\u662f\u6548\u7387\u6bd4\u8f83\u4f4e\u7684\u505a\u6cd5\uff0c\u5982\u679c<strong>\u4f7f\u7528if_else\u6765\u4ee3\u66ff\u7b2c\u4e00\u91cd\u5faa\u73af\uff0c\u5219\u4f1a\u53d8\u5f97\u975e\u5e38\u7b80\u6d01\u4e14\u5feb\u901f\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def isPalindrome(self, s: str) -&gt; bool:\n        head,tail=0,len(s)-1\n        while head&lt;tail:\n            if not s&#91;head].isalnum():\n                head+=1\n            elif not s&#91;tail].isalnum():\n                tail-=1\n            else:\n                if s&#91;head].lower()!=s&#91;tail].lower():\n                    return False\n                head+=1\n                tail-=1\n        return True<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.1.4<a href=\"https:\/\/leetcode.cn\/problems\/watering-plants-ii\/solutions\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/watering-plants-ii\/solutions\/\">\u7ed9\u690d\u7269\u6d47\u6c34\u2161<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">lice \u548c Bob \u6253\u7b97\u7ed9\u82b1\u56ed\u91cc\u7684&nbsp;<code>n<\/code>&nbsp;\u682a\u690d\u7269\u6d47\u6c34\u3002\u690d\u7269\u6392\u6210\u4e00\u884c\uff0c\u4ece\u5de6\u5230\u53f3\u8fdb\u884c\u6807\u8bb0\uff0c\u7f16\u53f7\u4ece&nbsp;<code>0<\/code>&nbsp;\u5230&nbsp;n &#8211; 1&nbsp;\u3002\u5176\u4e2d\uff0c\u7b2c&nbsp;<code>i<\/code>&nbsp;\u682a\u690d\u7269\u7684\u4f4d\u7f6e\u662f&nbsp;x = i&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u4e00\u682a\u690d\u7269\u90fd\u9700\u8981\u6d47\u7279\u5b9a\u91cf\u7684\u6c34\u3002Alice \u548c Bob \u6bcf\u4eba\u6709\u4e00\u4e2a\u6c34\u7f50\uff0c<strong>\u6700\u521d\u662f\u6ee1\u7684&nbsp;<\/strong>\u3002\u4ed6\u4eec\u6309\u4e0b\u9762\u63cf\u8ff0\u7684\u65b9\u5f0f\u5b8c\u6210\u6d47\u6c34\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&nbsp;Alice \u6309&nbsp;<strong>\u4ece\u5de6\u5230\u53f3<\/strong>&nbsp;\u7684\u987a\u5e8f\u7ed9\u690d\u7269\u6d47\u6c34\uff0c\u4ece\u690d\u7269&nbsp;<code>0<\/code>&nbsp;\u5f00\u59cb\u3002Bob \u6309&nbsp;<strong>\u4ece\u53f3\u5230\u5de6<\/strong>&nbsp;\u7684\u987a\u5e8f\u7ed9\u690d\u7269\u6d47\u6c34\uff0c\u4ece\u690d\u7269&nbsp;<code>n - 1<\/code>&nbsp;\u5f00\u59cb\u3002\u4ed6\u4eec&nbsp;<strong>\u540c\u65f6<\/strong>&nbsp;\u7ed9\u690d\u7269\u6d47\u6c34\u3002<\/li>\n\n\n\n<li>\u65e0\u8bba\u9700\u8981\u591a\u5c11\u6c34\uff0c\u4e3a\u6bcf\u682a\u690d\u7269\u6d47\u6c34\u6240\u9700\u7684\u65f6\u95f4\u90fd\u662f\u76f8\u540c\u7684\u3002<\/li>\n\n\n\n<li>\u5982\u679c Alice\/Bob \u6c34\u7f50\u4e2d\u7684\u6c34\u8db3\u4ee5&nbsp;<strong>\u5b8c\u5168<\/strong>&nbsp;\u704c\u6e89\u690d\u7269\uff0c\u4ed6\u4eec&nbsp;<strong>\u5fc5\u987b<\/strong>&nbsp;\u7ed9\u690d\u7269\u6d47\u6c34\u3002\u5426\u5219\uff0c\u4ed6\u4eec&nbsp;<strong>\u9996\u5148<\/strong>\uff08\u7acb\u5373\uff09\u91cd\u65b0\u88c5\u6ee1\u7f50\u5b50\uff0c\u7136\u540e\u7ed9\u690d\u7269\u6d47\u6c34\u3002<\/li>\n\n\n\n<li>\u5982\u679c Alice \u548c Bob \u5230\u8fbe\u540c\u4e00\u682a\u690d\u7269\uff0c\u90a3\u4e48\u5f53\u524d\u6c34\u7f50\u4e2d\u6c34&nbsp;<strong>\u66f4\u591a<\/strong>&nbsp;\u7684\u4eba\u4f1a\u7ed9\u8fd9\u682a\u690d\u7269\u6d47\u6c34\u3002\u5982\u679c\u4ed6\u4fe9\u6c34\u91cf\u76f8\u540c\uff0c\u90a3\u4e48 Alice \u4f1a\u7ed9\u8fd9\u682a\u690d\u7269\u6d47\u6c34\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece&nbsp;<strong>0<\/strong>&nbsp;\u5f00\u59cb\u7684\u6574\u6570\u6570\u7ec4&nbsp;plants&nbsp;\uff0c\u6570\u7ec4\u7531&nbsp;<code>n<\/code>&nbsp;\u4e2a\u6574\u6570\u7ec4\u6210\u3002\u5176\u4e2d\uff0cplants[i]&nbsp;\u4e3a\u7b2c&nbsp;<code>i<\/code>&nbsp;\u682a\u690d\u7269\u9700\u8981\u7684\u6c34\u91cf\u3002\u53e6\u6709\u4e24\u4e2a\u6574\u6570&nbsp;capacityA&nbsp;\u548c&nbsp;capacityB&nbsp;\u5206\u522b\u8868\u793a Alice \u548c Bob \u6c34\u7f50\u7684\u5bb9\u91cf\u3002\u8fd4\u56de\u4e24\u4eba\u6d47\u704c\u6240\u6709\u690d\u7269\u8fc7\u7a0b\u4e2d\u91cd\u65b0\u704c\u6ee1\u6c34\u7f50\u7684&nbsp;<strong>\u6b21\u6570<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>plants = [2,2,3,3], capacityA = 5, capacityB = 5\n<strong>\u8f93\u51fa\uff1a<\/strong>1\n<strong>\u89e3\u91ca\uff1a<\/strong>\n- \u6700\u521d\uff0cAlice \u548c Bob \u7684\u6c34\u7f50\u4e2d\u5404\u6709 5 \u5355\u5143\u6c34\u3002\n- Alice \u7ed9\u690d\u7269 0 \u6d47\u6c34\uff0cBob \u7ed9\u690d\u7269 3 \u6d47\u6c34\u3002\n- Alice \u548c Bob \u73b0\u5728\u5206\u522b\u5269\u4e0b 3 \u5355\u5143\u548c 2 \u5355\u5143\u6c34\u3002\n- Alice \u6709\u8db3\u591f\u7684\u6c34\u7ed9\u690d\u7269 1 \uff0c\u6240\u4ee5\u5979\u76f4\u63a5\u6d47\u6c34\u3002Bob \u7684\u6c34\u4e0d\u591f\u7ed9\u690d\u7269 2 \uff0c\u6240\u4ee5\u4ed6\u5148\u91cd\u65b0\u88c5\u6ee1\u6c34\uff0c\u518d\u6d47\u6c34\u3002\n\u6240\u4ee5\uff0c\u4e24\u4eba\u6d47\u704c\u6240\u6709\u690d\u7269\u8fc7\u7a0b\u4e2d\u91cd\u65b0\u704c\u6ee1\u6c34\u7f50\u7684\u6b21\u6570 = 0 + 0 + 1 + 0 = 1 \u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u9053\u9898\u76ee\u672c\u8d28\u4e0a\u662f\u56de\u6587\u4e32\u7684\u601d\u8def\uff0c\u5176\u4e3a\u9996\u5c3e\u6307\u9488\u7684\u540c\u6b65\u6d47\u6c34\u3002<strong>\u6ce8\u610f\uff0c\u662f\u540c\u6b65\u6d47\u6c34\uff0cA\u6d47\u6c34\u4e00\u6b21\uff0cB\u5c31\u5fc5\u987b\u6d47\u6c34\u4e00\u6b21\u3002<\/strong>\u672c\u8d28\u4e0a\u4e0e\u56de\u6587\u4e32\u7684\u5224\u522b\u5e76\u65e0\u533a\u522b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>class <\/em>Solution:\n    <em>def <\/em>minimumRefill(<em>self<\/em>, plants: List&#91;<em>int<\/em>], capacityA: <em>int<\/em>, capacityB: <em>int<\/em>) -> <em>int<\/em>:\n        head,tail=0,<em>len<\/em>(plants)-1\n        water_a=capacityA\n        water_b=capacityB\n        res=0\n        <em>while <\/em>head&lt;tail:\n            <em>if <\/em>water_a&lt;plants&#91;head]:\n                res+=1\n                water_a=capacityA\n            water_a-=plants&#91;head]\n            head+=1\n\n            <em>if <\/em>water_b&lt;plants&#91;tail]:\n                res+=1\n                water_b=capacityB\n            water_b-=plants&#91;tail]\n            tail-=1\n\n        <em>return <\/em>res+1 <em>if max<\/em>(water_b,water_a)&lt;plants&#91;head] <em>else <\/em>res<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.2\u5f02\u6b65\u76f8\u5411\u6307\u9488<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u8c13\u5f02\u6b65\u76f8\u5411\u6307\u9488\u5373\u662f\u5728\u76f8\u5411\u626b\u63cf\u8fc7\u7a0b\u4e2d\uff0chead\u4e0etail\u56e0\u4e3a\u4e00\u4e9b\u6761\u4ef6\u4f1a\u51fa\u73b0\u4e0d\u540c\u7a0b\u5ea6\u7684\u5f02\u6b65\u3002\u6bd4\u5982\u9009\u53d6\u4e24\u4e2a\u4e4b\u4e2d\u7684\u4e00\u4e2a\u4f5c\u4e3a\u7ed3\u679c\uff0c\u4e00\u4e2a\u79fb\u52a8\u4e00\u4e2a\u4e0d\u52a8\u3002\u4e5f\u6709\u5de6\u53f3\u5f02\u6b65\u79fb\u52a8\u4ee5\u6c42\u5f97\u4e00\u4e2a\u4e2d\u95f4\u533a\u95f4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.2.1<a href=\"https:\/\/leetcode.cn\/problems\/squares-of-a-sorted-array\/submissions\/667822700\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/squares-of-a-sorted-array\/submissions\/667822700\/\">\u6709\u5e8f\u6570\u7ec4\u7684\u5e73\u65b9<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a\u6309&nbsp;<strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong>&nbsp;\u6392\u5e8f\u7684\u6574\u6570\u6570\u7ec4&nbsp;nums\uff0c\u8fd4\u56de&nbsp;<strong>\u6bcf\u4e2a\u6570\u5b57\u7684\u5e73\u65b9<\/strong>&nbsp;\u7ec4\u6210\u7684\u65b0\u6570\u7ec4\uff0c\u8981\u6c42\u4e5f\u6309&nbsp;<strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong>&nbsp;\u6392\u5e8f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [-4,-1,0,3,10]\n<strong>\u8f93\u51fa\uff1a<\/strong>[0,1,9,16,100]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u5e73\u65b9\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [16,1,0,9,100]\n\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [0,1,9,16,100]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9009\u53d6\u9996\u5c3e\u66f4\u5927\u7684\u4e00\u4e2a\u503c\u4f5c\u4e3a\u65b0\u6570\u7ec4\u7684\u503c\u52a0\u5165\uff0c\u6700\u540e\u7ffb\u8f6c\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def sortedSquares(self, nums: List&#91;int]) -&gt; List&#91;int]:\n        head,tail=0,len(nums)-1\n        res=&#91;]\n        while head&lt;=tail:\n            a=pow(nums&#91;head],2)\n            b=pow(nums&#91;tail],2)\n            if a&gt;=b:\n                res.append(a)\n                head+=1\n            else:\n                res.append(b)\n                tail-=1\n        return res&#91;::-1]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.2.2<a href=\"https:\/\/leetcode.cn\/problems\/find-k-closest-elements\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/find-k-closest-elements\/\">\u627e\u5230K\u4e2a\u6700\u63a5\u8fd1\u7684\u5143\u7d20<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u5b9a\u4e00\u4e2a&nbsp;<strong>\u6392\u5e8f\u597d<\/strong>&nbsp;\u7684\u6570\u7ec4&nbsp;<code>arr<\/code>&nbsp;\uff0c\u4e24\u4e2a\u6574\u6570&nbsp;<code>k<\/code>&nbsp;\u548c&nbsp;<code>x<\/code>&nbsp;\uff0c\u4ece\u6570\u7ec4\u4e2d\u627e\u5230\u6700\u9760\u8fd1&nbsp;<code>x<\/code>\uff08\u4e24\u6570\u4e4b\u5dee\u6700\u5c0f\uff09\u7684&nbsp;<code>k<\/code>&nbsp;\u4e2a\u6570\u3002\u8fd4\u56de\u7684\u7ed3\u679c\u5fc5\u987b\u8981\u662f\u6309\u5347\u5e8f\u6392\u597d\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u6570&nbsp;<code>a<\/code>&nbsp;\u6bd4\u6574\u6570&nbsp;<code>b<\/code>&nbsp;\u66f4\u63a5\u8fd1&nbsp;<code>x<\/code>&nbsp;\u9700\u8981\u6ee1\u8db3\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>|a &#8211; x| &lt; |b &#8211; x|&nbsp;\u6216\u8005<\/li>\n\n\n\n<li>|a &#8211; x| == |b &#8211; x|&nbsp;\u4e14&nbsp;a &lt; b<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>arr = [1,2,3,4,5], k = 4, x = 3\n<strong>\u8f93\u51fa\uff1a<\/strong>[1,2,3,4]\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>arr = [1,1,2,3,4,5], k = 4, x = -1\n<strong>\u8f93\u51fa\uff1a<\/strong>[1,1,2,3]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u9898\u5c31\u662f\u5178\u578b\u5730\u901a\u8fc7\u5f02\u6b65\u76f8\u5411\u6307\u9488\u6c42\u4e2d\u95f4\u533a\u95f4\u3002\u5f53\u7136\uff0c\u4e5f\u6709\u975e\u5e38\u53d6\u5de7\u7684\u65b9\u6cd5\uff0c\u4e00\u884c\u4ee3\u7801\u5373\u53ef\u89e3\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e00\uff1a\u7edd\u5bf9\u503c\u6392\u5e8f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def findClosestElements(self, arr: List&#91;int], k: int, x: int) -&gt; List&#91;int]:\n        return sorted(sorted(arr,key=lambda num: abs(num-x))&#91;:k])<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e8c\uff1a\u5f02\u6b65\u76f8\u5411\u6307\u9488\u6c42\u4e2d\u95f4\u533a\u95f4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def findClosestElements(self, arr: List&#91;int], k: int, x: int) -&gt; List&#91;int]:\n        head,tail=0,len(arr)-1\n        while tail-head+1&gt;k:\n            if abs(arr&#91;head]-x)&gt;abs(arr&#91;tail]-x):\n                head+=1\n            else:\n                tail-=1\n        return arr&#91;head:tail+1]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e24\u79cd\u65b9\u6cd5\u90fd\u6bd4\u8f83\u7b80\u6d01\uff0c\u7b14\u8005\u63a8\u8350\u5168\u90e8\u638c\u63e1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.2.3<a href=\"https:\/\/leetcode.cn\/problems\/the-k-strongest-values-in-an-array\/description\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/the-k-strongest-values-in-an-array\/description\/\">\u6570\u7ec4\u79cd\u7684k\u4e2a\u6700\u5f3a\u503c<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;arr&nbsp;\u548c\u4e00\u4e2a\u6574\u6570&nbsp;<code>k<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbe&nbsp;<code>m<\/code>&nbsp;\u4e3a\u6570\u7ec4\u7684\u4e2d\u4f4d\u6570\uff0c\u53ea\u8981\u6ee1\u8db3\u4e0b\u8ff0\u4e24\u4e2a\u524d\u63d0\u4e4b\u4e00\uff0c\u5c31\u53ef\u4ee5\u5224\u5b9a&nbsp;arr[i]&nbsp;\u7684\u503c\u6bd4&nbsp;arr[j]&nbsp;\u7684\u503c\u66f4\u5f3a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&nbsp;|arr[i] &#8211; m| &gt; |arr[j]&nbsp;&#8211; m|<\/li>\n\n\n\n<li>&nbsp;|arr[i] &#8211; m| == |arr[j] &#8211; m|\uff0c\u4e14&nbsp;arr[i] &gt; arr[j]<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u8fd4\u56de\u7531\u6570\u7ec4\u4e2d\u6700\u5f3a\u7684&nbsp;<code>k<\/code>&nbsp;\u4e2a\u503c\u7ec4\u6210\u7684\u5217\u8868\u3002\u7b54\u6848\u53ef\u4ee5\u4ee5&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e2d\u4f4d\u6570<\/strong>&nbsp;\u662f\u4e00\u4e2a\u6709\u5e8f\u6574\u6570\u5217\u8868\u4e2d\u5904\u4e8e\u4e2d\u95f4\u4f4d\u7f6e\u7684\u503c\u3002\u5f62\u5f0f\u4e0a\uff0c\u5982\u679c\u5217\u8868\u7684\u957f\u5ea6\u4e3a&nbsp;<code>n<\/code>&nbsp;\uff0c\u90a3\u4e48\u4e2d\u4f4d\u6570\u5c31\u662f\u8be5\u6709\u5e8f\u5217\u8868\uff08\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff09\u4e2d\u4f4d\u4e8e&nbsp;<code>((<\/code>n<code> - 1) \/ 2)<\/code>&nbsp;\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5982&nbsp;<code>arr =&nbsp;[6, -3,<\/code> <code>7, 2, 11]<\/code>\uff0cn = 5\uff1a\u6570\u7ec4\u6392\u5e8f\u540e\u5f97\u5230&nbsp;arr = [-3, 2, 6, 7, 11]&nbsp;\uff0c\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u4e3a&nbsp;m = ((5 &#8211; 1) \/ 2) = 2&nbsp;\uff0c\u4e2d\u4f4d\u6570&nbsp;arr[m]&nbsp;\u7684\u503c\u4e3a&nbsp;<code>6<\/code>&nbsp;\u3002<\/li>\n\n\n\n<li>\u4f8b\u5982&nbsp;<code>arr =&nbsp;[-7, 22,<\/code> <code>17,\u20093]<\/code>\uff0c<code>n = 4<\/code>\uff1a\u6570\u7ec4\u6392\u5e8f\u540e\u5f97\u5230&nbsp;arr = [-7, 3, 17, 22]&nbsp;\uff0c\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u4e3a&nbsp;m = ((4 &#8211; 1) \/ 2) = 1&nbsp;\uff0c\u4e2d\u4f4d\u6570&nbsp;arr[m]&nbsp;\u7684\u503c\u4e3a&nbsp;<code>3<\/code>&nbsp;\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>arr = [1,2,3,4,5], k = 2\n<strong>\u8f93\u51fa\uff1a<\/strong>[5,1]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u4e2d\u4f4d\u6570\u4e3a 3\uff0c\u6309\u4ece\u5f3a\u5230\u5f31\u987a\u5e8f\u6392\u5e8f\u540e\uff0c\u6570\u7ec4\u53d8\u4e3a [5,1,4,2,3]\u3002\u6700\u5f3a\u7684\u4e24\u4e2a\u5143\u7d20\u662f [5, 1]\u3002[1, 5] \u4e5f\u662f\u6b63\u786e\u7b54\u6848\u3002\n\u6ce8\u610f\uff0c\u5c3d\u7ba1 |5 - 3| == |1 - 3| \uff0c\u4f46\u662f 5 \u6bd4 1 \u66f4\u5f3a\uff0c\u56e0\u4e3a 5 &gt; 1 \u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u9898\u5176\u5b9e\u5c31\u662f\u4e0a\u4e00\u9898\u7684\u53cd\u9762\uff0c\u76f4\u63a5\u7167\u6284\u4e0a\u4e00\u9898\u4ee3\u7801\u7136\u540e\u7ffb\u8f6c\u4e00\u4e0b\u5c31\u884c\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def getStrongest(self, arr: List&#91;int], k: int) -&gt; List&#91;int]:\n        length=len(arr)-k\n        arr=sorted(arr)\n        x=arr&#91;(len(arr)-1)\/\/2]\n        head,tail=0,len(arr)-1\n        while tail-head+1&gt;length:\n            if abs(arr&#91;head]-x)&gt;abs(arr&#91;tail]-x):\n                head+=1\n            else:\n                tail-=1\n        return arr&#91;:head]+arr&#91;tail+1:]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b2.2.4<a href=\"https:\/\/leetcode.cn\/problems\/two-sum-ii-input-array-is-sorted\/\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/two-sum-ii-input-array-is-sorted\/\">\u4e24\u6570\u4e4b\u548c\u2161<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u4f60\u4e00\u4e2a\u4e0b\u6807\u4ece&nbsp;<strong>1<\/strong>&nbsp;\u5f00\u59cb\u7684\u6574\u6570\u6570\u7ec4&nbsp;numbers&nbsp;\uff0c\u8be5\u6570\u7ec4\u5df2\u6309<strong><em>&nbsp;<\/em>\u975e\u9012\u51cf\u987a\u5e8f\u6392\u5217&nbsp;&nbsp;<\/strong>\uff0c\u8bf7\u4f60\u4ece\u6570\u7ec4\u4e2d\u627e\u51fa\u6ee1\u8db3\u76f8\u52a0\u4e4b\u548c\u7b49\u4e8e\u76ee\u6807\u6570&nbsp;target&nbsp;\u7684\u4e24\u4e2a\u6570\u3002\u5982\u679c\u8bbe\u8fd9\u4e24\u4e2a\u6570\u5206\u522b\u662f&nbsp;numbers[index<sub>1<\/sub>]&nbsp;\u548c&nbsp;numbers[index<sub>2<\/sub>]&nbsp;\uff0c\u5219&nbsp;1 &lt;= index<sub>1<\/sub> &lt; index<sub>2<\/sub> &lt;= numbers.length&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u957f\u5ea6\u4e3a 2 \u7684\u6574\u6570\u6570\u7ec4&nbsp;[index<sub>1<\/sub>, index<sub>2<\/sub>]&nbsp;\u7684\u5f62\u5f0f\u8fd4\u56de\u8fd9\u4e24\u4e2a\u6574\u6570\u7684\u4e0b\u6807&nbsp;index<sub>1<\/sub><em>&nbsp;<\/em>\u548c<em>&nbsp;<\/em>index<sub>2<\/sub>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u5047\u8bbe\u6bcf\u4e2a\u8f93\u5165&nbsp;<strong>\u53ea\u5bf9\u5e94\u552f\u4e00\u7684\u7b54\u6848<\/strong>&nbsp;\uff0c\u800c\u4e14\u4f60&nbsp;<strong>\u4e0d\u53ef\u4ee5<\/strong>&nbsp;\u91cd\u590d\u4f7f\u7528\u76f8\u540c\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u6240\u8bbe\u8ba1\u7684\u89e3\u51b3\u65b9\u6848\u5fc5\u987b\u53ea\u4f7f\u7528\u5e38\u91cf\u7ea7\u7684\u989d\u5916\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>numbers = [<strong><em>2<\/em><\/strong>,<strong><em>7<\/em><\/strong>,11,15], target = 9\n<strong>\u8f93\u51fa\uff1a<\/strong>[1,2]\n<strong>\u89e3\u91ca\uff1a<\/strong>2 \u4e0e 7 \u4e4b\u548c\u7b49\u4e8e\u76ee\u6807\u6570 9 \u3002\u56e0\u6b64 index<sub>1<\/sub> = 1, index<sub>2<\/sub> = 2 \u3002\u8fd4\u56de [1, 2] \u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u9898\u5373\u662f\u4f7f\u7528\u5f02\u6b65\u6307\u9488\u641c\u7d22\u4e00\u4e2a\u5143\u7ec4\u3002\u56e0\u4e3a\u6570\u7ec4\u662f\u6709\u5e8f\u7684\uff0c\u6240\u4ee5\u53ef\u4ee5\u7528\u5f02\u6b65\u6307\u9488\u641c\u7d22\u548c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    def twoSum(self, numbers: List&#91;int], target: int) -&gt; List&#91;int]:\n        left,right=0,len(numbers)-1\n        while left&lt;right:\n            cur_sum=numbers&#91;left]+numbers&#91;right]\n            if cur_sum&gt;target:\n                right-=1\n            elif cur_sum&lt;target:\n                left+=1\n            else:\n                return &#91;left+1,right+1]\n        return &#91;]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u7cfb\u7edf\u5b66\u4e60\u4e86\u90e8\u5206\u53cc\u6307\u9488\u7b97\u6cd5\u7684\u6280\u5de7\uff0c\u5728\u6b64\u7cfb\u7edf\u603b\u7ed3\u4e00\u4e0b\u3002 \u4e00\uff0c\u5f15\u8a00 \u53cc\u6307\u9488\u90e8\u5206\u7684\u9898\u76ee\u975e\u5e38\u591a\uff0c\u7075\u6d3b\u6027\u6bd4\u8f83\u9ad8\uff0c\u603b\u7ed3\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":54,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learning"],"_links":{"self":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":7,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions\/127"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/media\/54"}],"wp:attachment":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}