{"id":167,"date":"2026-03-16T17:56:40","date_gmt":"2026-03-16T09:56:40","guid":{"rendered":"https:\/\/sunsyblog.cn\/?p=167"},"modified":"2026-03-25T16:03:35","modified_gmt":"2026-03-25T08:03:35","slug":"leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02","status":"publish","type":"post","link":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/","title":{"rendered":"LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">65.<a href=\"https:\/\/leetcode.cn\/problems\/letter-combinations-of-a-phone-number\/\" target=\"_blank\"  rel=\"nofollow\" >\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57&nbsp;<code>2-9<\/code>&nbsp;\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u6240\u6709\u5b83\u80fd\u8868\u793a\u7684\u5b57\u6bcd\u7ec4\u5408\u3002\u7b54\u6848\u53ef\u4ee5\u6309&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u3002<\/p>\n\n\n\n<p>\u7ed9\u51fa\u6570\u5b57\u5230\u5b57\u6bcd\u7684\u6620\u5c04\u5982\u4e0b\uff08\u4e0e\u7535\u8bdd\u6309\u952e\u76f8\u540c\uff09\u3002\u6ce8\u610f 1 \u4e0d\u5bf9\u5e94\u4efb\u4f55\u5b57\u6bcd\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>digits = \"23\"<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>[\"ad\",\"ae\",\"af\",\"bd\",\"be\",\"bf\",\"cd\",\"ce\",\"cf\"]<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u6cd51\uff1a\u904d\u5386\u6240\u6709\u7ed3\u679c\uff0c\u6784\u9020\u5b57\u7b26\u4e32<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def letterCombinations(self, digits: str) -&gt; List&#91;str]:\n        num_str={\n            '2':'abc',\n            '3':'def',\n            '4':'ghi',\n            '5':'jkl',\n            '6':'mno',\n            '7':'pqrs',\n            '8':'tuv',\n            '9':'wxyz'\n        }\n        ans=&#91;&#91;]]\n        for i in digits:\n            i_str=num_str&#91;i]\n            path=&#91;]\n            for j in  ans:\n                for c in i_str:\n                    temp=j&#91;:]\n                    temp.append(c)\n                    path.append(temp)\n            ans=path&#91;:]\n        res=&#91;]\n        for i in ans:\n            res.append(''.join(i))\n\n        return res<\/code><\/pre>\n\n\n\n<p>\u6cd52\uff1a\u9012\u5f52\u56de\u6eaf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def letterCombinations(self, digits: str) -&gt; List&#91;str]:\n        num_str={\n            '2':'abc',\n            '3':'def',\n            '4':'ghi',\n            '5':'jkl',\n            '6':'mno',\n            '7':'pqrs',\n            '8':'tuv',\n            '9':'wxyz'\n        }\n        n = len(digits)\n        if n == 0:\n            return &#91;]\n  \n        ans = &#91;]\n        path = &#91;''] * n  # \u6ce8\u610f path \u957f\u5ea6\u4e00\u5f00\u59cb\u5c31\u662f n\uff0c\u4e0d\u662f\u7a7a\u5217\u8868\n\n        def dfs(i: int) -&gt; None:\n            if i == n:\n                ans.append(''.join(path))\n                return\n            for c in num_str&#91;digits&#91;i]]:\n                path&#91;i] = c  # \u76f4\u63a5\u8986\u76d6\n                dfs(i + 1)\n\n        dfs(0)\n        return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">66.<a href=\"https:\/\/leetcode.cn\/problems\/decode-string\/\" target=\"_blank\"  rel=\"nofollow\" >\u5b57\u7b26\u4e32\u89e3\u7801<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u7ecf\u8fc7\u7f16\u7801\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5b83\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p>\u7f16\u7801\u89c4\u5219\u4e3a:&nbsp;<code>k[encoded_string]<\/code>\uff0c\u8868\u793a\u5176\u4e2d\u65b9\u62ec\u53f7\u5185\u90e8\u7684&nbsp;<code>encoded_string<\/code>&nbsp;\u6b63\u597d\u91cd\u590d&nbsp;<code>k<\/code>&nbsp;\u6b21\u3002\u6ce8\u610f&nbsp;<code>k<\/code>&nbsp;\u4fdd\u8bc1\u4e3a\u6b63\u6574\u6570\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u8f93\u5165\u5b57\u7b26\u4e32\u603b\u662f\u6709\u6548\u7684\uff1b\u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u6ca1\u6709\u989d\u5916\u7684\u7a7a\u683c\uff0c\u4e14\u8f93\u5165\u7684\u65b9\u62ec\u53f7\u603b\u662f\u7b26\u5408\u683c\u5f0f\u8981\u6c42\u7684\u3002<\/p>\n\n\n\n<p>\u6b64\u5916\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u539f\u59cb\u6570\u636e\u4e0d\u5305\u542b\u6570\u5b57\uff0c\u6240\u6709\u7684\u6570\u5b57\u53ea\u8868\u793a\u91cd\u590d\u7684\u6b21\u6570&nbsp;<code>k<\/code>&nbsp;\uff0c\u4f8b\u5982\u4e0d\u4f1a\u51fa\u73b0\u50cf&nbsp;<code>3a<\/code>&nbsp;\u6216&nbsp;<code>2[4]<\/code>&nbsp;\u7684\u8f93\u5165\u3002<\/p>\n\n\n\n<p>\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1\u8f93\u51fa\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7&nbsp;<code>10<sup>5<\/sup><\/code>\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>s = \"3[a]2[bc]\"<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>\"aaabcbc\"<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u9012\u5f52\uff0c\u5f53\u5b57\u7b26\u4e3a\u6570\u5b57\u65f6\uff0c\u8ba1\u7b97k\uff0c\u5f53\u5b57\u7b26\u4e3a\u5b57\u6bcd\u65f6\uff0c\u5411res\u4e2d\u52a0\uff0c\u5f53\u5b57\u7b26\u4e3a\u2018[\u2019\u65f6\uff0c\u8bf4\u660e\u91cd\u590d\u5f00\u59cb\uff0c\u5f53\u524dk\u4e3a\u91cd\u590d\u6b21\u6570\uff0c\u5f53\u5b57\u7b26\u4e3a\u2018[\u2019\u65f6\uff0c\u8bf4\u660e\u91cd\u590d\u7ed3\u675f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def decodeString(self, s: str) -&gt; str:\n        i=0\n        def decode()-&gt;str:\n            nonlocal i\n            res=''\n            k=0\n            while i&lt;len(s):\n                c=s&#91;i]\n                i+=1\n                if  '0'&lt;=c&lt;='9':\n                    k=k*10+int(c)\n                elif 'a'&lt;=c&lt;='z':\n                    res+=c \n                elif c=='&#91;':\n                    res+=decode()*k\n                    k=0\n                elif c==']':\n                    break\n            return res\n       \n        return  decode()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">67.<a href=\"https:\/\/leetcode.cn\/problems\/kth-largest-element-in-an-array\/\" target=\"_blank\"  rel=\"nofollow\" >\u6570\u7ec4\u4e2d\u7684\u7b2cK\u4e2a\u6700\u5927\u5143\u7d20<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\u548c\u6574\u6570&nbsp;<code>k<\/code>\uff0c\u8bf7\u8fd4\u56de\u6570\u7ec4\u4e2d\u7b2c&nbsp;<code><strong>k<\/strong><\/code>&nbsp;\u4e2a\u6700\u5927\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u4f60\u9700\u8981\u627e\u7684\u662f\u6570\u7ec4\u6392\u5e8f\u540e\u7684\u7b2c&nbsp;<code>k<\/code>&nbsp;\u4e2a\u6700\u5927\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u7b2c&nbsp;<code>k<\/code>&nbsp;\u4e2a\u4e0d\u540c\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u4f60\u5fc5\u987b\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a&nbsp;<code>O(n)<\/code>&nbsp;\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165:<\/strong> <code>[3,2,1,5,6,4],<\/code> k = 2<\/li>\n\n\n\n<li><strong>\u8f93\u51fa:<\/strong> 5<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u901a\u8fc7\u5feb\u6392\u903b\u8f91\u5feb\u901f\u5b9a\u4f4d\u7b2ck\u5927\u5143\u7d20\u4f4d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def partition(self,nums:List&#91;int],left:int,right:int)-&gt;int:\n\n        i=randint(left,right)\n        povit=nums&#91;i]\n\n        nums&#91;left],nums&#91;i]=nums&#91;i],nums&#91;left]\n\n        l,r=left+1,right\n\n        while True:\n            while l&lt;=r and nums&#91;l]&lt;povit:\n                l+=1\n            while l&lt;=r and nums&#91;r]&gt;povit:\n                r-=1\n            if l&gt;=r:\n                break\n            nums&#91;l],nums&#91;r]=nums&#91;r],nums&#91;l]\n            l+=1\n            r-=1\n        nums&#91;left],nums&#91;r]=nums&#91;r],nums&#91;left]\n        return r\n\n    def findKthLargest(self, nums: List&#91;int], k: int) -&gt; int:\n        target_num=len(nums)-k\n        left,right=0,len(nums)-1\n        while True:\n            i=self.partition(nums,left,right)\n            if i==target_num:\n                return nums&#91;i]\n            elif i&gt;target_num:\n                right=i-1\n            elif i&lt;target_num:\n                left=i+1\n\n        <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">68.<a href=\"https:\/\/leetcode.cn\/problems\/combination-sum\/\" target=\"_blank\"  rel=\"nofollow\" >\u7ec4\u5408\u603b\u548c<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a&nbsp;<strong>\u65e0\u91cd\u590d\u5143\u7d20<\/strong>&nbsp;\u7684\u6574\u6570\u6570\u7ec4&nbsp;<code>candidates<\/code>&nbsp;\u548c\u4e00\u4e2a\u76ee\u6807\u6574\u6570&nbsp;<code>target<\/code>&nbsp;\uff0c\u627e\u51fa&nbsp;<code>candidates<\/code>&nbsp;\u4e2d\u53ef\u4ee5\u4f7f\u6570\u5b57\u548c\u4e3a\u76ee\u6807\u6570&nbsp;<code>target<\/code>&nbsp;\u7684 \u6240\u6709<em>&nbsp;<\/em><strong>\u4e0d\u540c\u7ec4\u5408<\/strong>&nbsp;\uff0c\u5e76\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u3002\u4f60\u53ef\u4ee5\u6309&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u8fd9\u4e9b\u7ec4\u5408\u3002<\/p>\n\n\n\n<p><code>candidates<\/code>&nbsp;\u4e2d\u7684&nbsp;<strong>\u540c\u4e00\u4e2a<\/strong>&nbsp;\u6570\u5b57\u53ef\u4ee5&nbsp;<strong>\u65e0\u9650\u5236\u91cd\u590d\u88ab\u9009\u53d6<\/strong>&nbsp;\u3002\u5982\u679c\u81f3\u5c11\u4e00\u4e2a\u6570\u5b57\u7684\u88ab\u9009\u6570\u91cf\u4e0d\u540c\uff0c\u5219\u4e24\u79cd\u7ec4\u5408\u662f\u4e0d\u540c\u7684\u3002&nbsp;<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u8f93\u5165\uff0c\u4fdd\u8bc1\u548c\u4e3a&nbsp;<code>target<\/code>&nbsp;\u7684\u4e0d\u540c\u7ec4\u5408\u6570\u5c11\u4e8e&nbsp;<code>150<\/code>&nbsp;\u4e2a\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>candidates = [2,3,6,7], target = 7<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>[[2,2,3],[7]]<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong><\/li>\n\n\n\n<li>2 \u548c 3 \u53ef\u4ee5\u5f62\u6210\u4e00\u7ec4\u5019\u9009\uff0c2 + 2 + 3 = 7 \u3002\u6ce8\u610f 2 \u53ef\u4ee5\u4f7f\u7528\u591a\u6b21\u3002<\/li>\n\n\n\n<li>7 \u4e5f\u662f\u4e00\u4e2a\u5019\u9009\uff0c 7 = 7 \u3002<\/li>\n\n\n\n<li>\u4ec5\u6709\u8fd9\u4e24\u79cd\u7ec4\u5408\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u6bcf\u6b21\u9009\u62e9\u9009\u6216\u4e0d\u9009\uff0c\u9012\u5f52\u56de\u6eaf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def combinationSum(self, candidates: List&#91;int], target: int) -&gt; List&#91;List&#91;int]]:\n        candidates.sort()\n        ans = &#91;]\n        path = &#91;]\n\n        def dfs(i: int, left: int) -&gt; None:\n            if left == 0:\n                # \u627e\u5230\u4e00\u4e2a\u5408\u6cd5\u7ec4\u5408\n                ans.append(path.copy())\n                return\n\n            if i == len(candidates) or left &lt; candidates&#91;i]:\n                return\n\n            # \u4e0d\u9009\n            dfs(i + 1, left)\n\n            # \u9009\n            path.append(candidates&#91;i])\n            dfs(i, left - candidates&#91;i])\n            path.pop()  # \u6062\u590d\u73b0\u573a\n\n        dfs(0, target)\n        return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">69.<a href=\"https:\/\/leetcode.cn\/problems\/search-in-rotated-sorted-array\/\" target=\"_blank\"  rel=\"nofollow\" >\u641c\u7d22\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4<\/a><\/h2>\n\n\n\n<p>\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\u6309\u5347\u5e8f\u6392\u5217\uff0c\u6570\u7ec4\u4e2d\u7684\u503c&nbsp;<strong>\u4e92\u4e0d\u76f8\u540c<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u5728\u4f20\u9012\u7ed9\u51fd\u6570\u4e4b\u524d\uff0c<code>nums<\/code>&nbsp;\u5728\u9884\u5148\u672a\u77e5\u7684\u67d0\u4e2a\u4e0b\u6807&nbsp;<code>k<\/code>\uff08<code>0 &lt;= k &lt; nums.length<\/code>\uff09\u4e0a\u8fdb\u884c\u4e86&nbsp;<strong>\u5411\u5de6\u65cb\u8f6c<\/strong>\uff0c\u4f7f\u6570\u7ec4\u53d8\u4e3a&nbsp;<code>[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]<\/code>\uff08\u4e0b\u6807&nbsp;<strong>\u4ece 0 \u5f00\u59cb<\/strong>&nbsp;\u8ba1\u6570\uff09\u3002\u4f8b\u5982\uff0c&nbsp;<code>[0,1,2,4,5,6,7]<\/code>&nbsp;\u4e0b\u6807&nbsp;<code>3<\/code>&nbsp;\u4e0a\u5411\u5de6\u65cb\u8f6c\u540e\u53ef\u80fd\u53d8\u4e3a&nbsp;<code>[4,5,6,7,0,1,2]<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u7ed9\u4f60&nbsp;<strong>\u65cb\u8f6c\u540e<\/strong>&nbsp;\u7684\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\u548c\u4e00\u4e2a\u6574\u6570&nbsp;<code>target<\/code>&nbsp;\uff0c\u5982\u679c&nbsp;<code>nums<\/code>&nbsp;\u4e2d\u5b58\u5728\u8fd9\u4e2a\u76ee\u6807\u503c&nbsp;<code>target<\/code>&nbsp;\uff0c\u5219\u8fd4\u56de\u5b83\u7684\u4e0b\u6807\uff0c\u5426\u5219\u8fd4\u56de&nbsp;<code>-1<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u4f60\u5fc5\u987b\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a&nbsp;<code>O(log n)<\/code>&nbsp;\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>nums = [4,5,6,7,0,1,2], target = 0<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>4<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u627e\u5230\u6700\u5c0f\u503c\u4f4d\u7f6e\uff0c\u5206\u6210\u4e24\u6bb5\u4e8c\u5206\u67e5\u627e\uff0c\u95ed\u533a\u95f4\u5199\u6cd5\u6ce8\u610f\u8d8a\u754c\u5224\u5b9a\u5904\u7406<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def findmin(self,nums:List&#91;int])-&gt;int:\n        left,right=0,len(nums)-1\n        while left&lt;=right:\n            mid=(left+right)\/\/2\n            if nums&#91;mid]&lt;nums&#91;-1]:\n                right=mid-1\n            else:\n                left=mid+1\n        if left&lt;0:\n            return 0\n        elif left&gt;len(nums)-1:\n            return len(nums)-1\n        else:\n            return left\n\n    def erfen(self, nums: List&#91;int], target: int,left:int,right:int)-&gt;int:\n        while left&lt;=right:\n            mid=(left+right)\/\/2\n            if nums&#91;mid]&lt;target:\n                left=mid+1\n            else:\n                right=mid-1\n        if 0 &lt;= left &lt; len(nums) and nums&#91;left] == target:\n            return left\n        else:\n            return -1\n\n    def search(self, nums: List&#91;int], target: int) -&gt; int:\n        if not nums:\n            return -1\n        k=self.findmin(nums)\n        if target&gt;nums&#91;-1]:\n            return self.erfen(nums,target,0,k-1)\n        else :\n            return self.erfen(nums,target,k,len(nums)-1)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">70.<a href=\"https:\/\/leetcode.cn\/problems\/top-k-frequent-elements\/\" target=\"_blank\"  rel=\"nofollow\" >\u524d K \u4e2a\u9ad8\u9891\u5143\u7d20<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\u548c\u4e00\u4e2a\u6574\u6570&nbsp;<code>k<\/code>&nbsp;\uff0c\u8bf7\u4f60\u8fd4\u56de\u5176\u4e2d\u51fa\u73b0\u9891\u7387\u524d&nbsp;<code>k<\/code>&nbsp;\u9ad8\u7684\u5143\u7d20\u3002\u4f60\u53ef\u4ee5\u6309&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u7b54\u6848\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<p><strong>\u8f93\u5165\uff1a<\/strong>nums = [1,1,1,2,2,3], k = 2<\/p>\n\n\n\n<p><strong>\u8f93\u51fa\uff1a<\/strong>[1,2]<\/p>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u7edf\u8ba1\u9891\u7387\u540e\u4ee5\u9891\u7387\u4e3akey\u8fdb\u884c\u6876\u6392\u5e8f\uff0c\u518d\u53cd\u5411\u904d\u5386\u5408\u5e76\u524dk\u9ad8\u4e2a\u5143\u7d20<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def topKFrequent(self, nums: List&#91;int], k: int) -&gt; List&#91;int]:\n        # \u7b2c\u4e00\u6b65\uff1a\u7edf\u8ba1\u6bcf\u4e2a\u5143\u7d20\u7684\u51fa\u73b0\u6b21\u6570\n        cnt = Counter(nums)\n        max_cnt = max(cnt.values())\n\n        # \u7b2c\u4e8c\u6b65\uff1a\u628a\u51fa\u73b0\u6b21\u6570\u76f8\u540c\u7684\u5143\u7d20\uff0c\u653e\u5230\u540c\u4e00\u4e2a\u6876\u4e2d\n        buckets = &#91;&#91;] for _ in range(max_cnt + 1)]  # \u4e5f\u53ef\u4ee5\u7528 defaultdict(list)\n        for x, c in cnt.items():\n            buckets&#91;c].append(x)\n\n        # \u7b2c\u4e09\u6b65\uff1a\u5012\u5e8f\u904d\u5386 buckets\uff0c\u628a\u51fa\u73b0\u6b21\u6570\u524d k \u5927\u7684\u5143\u7d20\u52a0\u5165\u7b54\u6848\n        ans = &#91;]\n        for bucket in buckets&#91;::-1]:\n            ans += bucket\n            # \u6ce8\u610f\u9898\u76ee\u4fdd\u8bc1\u7b54\u6848\u552f\u4e00\uff0c\u4e00\u5b9a\u4f1a\u51fa\u73b0\u6070\u597d\u7b49\u4e8e k \u7684\u60c5\u51b5\n            if len(ans) == k:\n                return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">71.<a href=\"https:\/\/leetcode.cn\/problems\/pascals-triangle\/\" target=\"_blank\"  rel=\"nofollow\" >\u6768\u8f89\u4e09\u89d2<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570&nbsp;<em><code>numRows<\/code>\uff0c<\/em>\u751f\u6210\u300c\u6768\u8f89\u4e09\u89d2\u300d\u7684\u524d&nbsp;<em><code>numRows<\/code>&nbsp;<\/em>\u884c\u3002<\/p>\n\n\n\n<p>\u5728<strong>\u300c\u6768\u8f89\u4e09\u89d2\u300d<\/strong>\u4e2d\uff0c\u6bcf\u4e2a\u6570\u662f\u5b83\u5de6\u4e0a\u65b9\u548c\u53f3\u4e0a\u65b9\u7684\u6570\u7684\u548c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic.leetcode.cn\/1626927345-DZmfxB-PascalTriangleAnimated2.gif\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165:<\/strong> numRows = 5<\/li>\n\n\n\n<li><strong>\u8f93\u51fa:<\/strong> [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>nums[i][j]=nums[i-1][j-1]+nums[i-1][j]<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def generate(self, numRows: int) -&gt; List&#91;List&#91;int]]:\n        ans=&#91;&#91;1]*(i+1)for i in range(numRows)]\n        for i in range(2,numRows):\n            for j in range(1,i):\n                ans&#91;i]&#91;j]=ans&#91;i-1]&#91;j-1]+ans&#91;i-1]&#91;j]\n        return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">72.<a href=\"https:\/\/leetcode.cn\/problems\/house-robber\/\" target=\"_blank\"  rel=\"nofollow\" >\u6253\u5bb6\u52ab\u820d<\/a><\/h2>\n\n\n\n<p>\u4f60\u662f\u4e00\u4e2a\u4e13\u4e1a\u7684\u5c0f\u5077\uff0c\u8ba1\u5212\u5077\u7a83\u6cbf\u8857\u7684\u623f\u5c4b\u3002\u6bcf\u95f4\u623f\u5185\u90fd\u85cf\u6709\u4e00\u5b9a\u7684\u73b0\u91d1\uff0c\u5f71\u54cd\u4f60\u5077\u7a83\u7684\u552f\u4e00\u5236\u7ea6\u56e0\u7d20\u5c31\u662f\u76f8\u90bb\u7684\u623f\u5c4b\u88c5\u6709\u76f8\u4e92\u8fde\u901a\u7684\u9632\u76d7\u7cfb\u7edf\uff0c<strong>\u5982\u679c\u4e24\u95f4\u76f8\u90bb\u7684\u623f\u5c4b\u5728\u540c\u4e00\u665a\u4e0a\u88ab\u5c0f\u5077\u95ef\u5165\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u62a5\u8b66<\/strong>\u3002<\/p>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4ee3\u8868\u6bcf\u4e2a\u623f\u5c4b\u5b58\u653e\u91d1\u989d\u7684\u975e\u8d1f\u6574\u6570\u6570\u7ec4\uff0c\u8ba1\u7b97\u4f60<strong>&nbsp;\u4e0d\u89e6\u52a8\u8b66\u62a5\u88c5\u7f6e\u7684\u60c5\u51b5\u4e0b&nbsp;<\/strong>\uff0c\u4e00\u591c\u4e4b\u5185\u80fd\u591f\u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>[1,2,3,1]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>4<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong>\u5077\u7a83 1 \u53f7\u623f\u5c4b (\u91d1\u989d = 1) \uff0c\u7136\u540e\u5077\u7a83 3 \u53f7\u623f\u5c4b (\u91d1\u989d = 3)\u3002<\/li>\n\n\n\n<li>&nbsp;    \u5077\u7a83\u5230\u7684\u6700\u9ad8\u91d1\u989d = 1 + 3 = 4 \u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>#ans[i+2]=max(ans[i]+nums[i],ans[i+1])<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def rob(self, nums: List&#91;int]) -&gt; int:\n        #ans&#91;i+2]=max(ans&#91;i]+nums&#91;i],ans&#91;i+1])\n        ans=&#91;0]*(len(nums)+2)\n        for i in range(0,len(nums)):\n            ans&#91;i+2]=max(ans&#91;i+1],ans&#91;i]+nums&#91;i])\n        return ans&#91;-1]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">73.<a href=\"https:\/\/leetcode.cn\/problems\/generate-parentheses\/\" target=\"_blank\"  rel=\"nofollow\" >\u62ec\u53f7\u751f\u6210<\/a><\/h2>\n\n\n\n<p>\u6570\u5b57&nbsp;<code>n<\/code>&nbsp;\u4ee3\u8868\u751f\u6210\u62ec\u53f7\u7684\u5bf9\u6570\uff0c\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u80fd\u591f\u751f\u6210\u6240\u6709\u53ef\u80fd\u7684\u5e76\u4e14&nbsp;<strong>\u6709\u6548\u7684&nbsp;<\/strong>\u62ec\u53f7\u7ec4\u5408\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>n = 3<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>[\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u9009\u6216\u4e0d\u9009\uff0cdfs(left,right),left\u4e3a\u5de6\u62ec\u53f7\u6570\uff0cright\u4e3a\u53f3\u62ec\u53f7\u6570\uff0cleft\u5c0f\u4e8en\u5219\u53ef\u9009\u5de6\u62ec\u53f7\uff0cright\u5c0f\u4e8eleft\u5219\u53ef\u9009\u53f3\u62ec\u53f7\uff0cright\u4e3an\u662f\u7ed3\u675f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def generateParenthesis(self, n: int) -&gt; List&#91;str]:\n        ans=&#91;]\n        path=&#91;'']*(2*n)\n        def dfs(Left:int,right:int)-&gt;None:\n            if right==n:\n                ans.append(''.join(path))\n                return\n            if Left&lt;n:\n                path&#91;Left+right]='('\n                dfs(Left+1,right)\n            if right&lt;Left:\n                path&#91;Left+right]=')'\n                dfs(Left,right+1)\n        dfs(0,0)\n        return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">74.<a href=\"https:\/\/leetcode.cn\/problems\/word-search\/\" target=\"_blank\"  rel=\"nofollow\" >\u5355\u8bcd\u641c\u7d22<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a&nbsp;<code>m x n<\/code>&nbsp;\u4e8c\u7ef4\u5b57\u7b26\u7f51\u683c&nbsp;<code>board<\/code>&nbsp;\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5355\u8bcd&nbsp;<code>word<\/code>&nbsp;\u3002\u5982\u679c&nbsp;<code>word<\/code>&nbsp;\u5b58\u5728\u4e8e\u7f51\u683c\u4e2d\uff0c\u8fd4\u56de&nbsp;<code>true<\/code>&nbsp;\uff1b\u5426\u5219\uff0c\u8fd4\u56de&nbsp;<code>false<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u5355\u8bcd\u5fc5\u987b\u6309\u7167\u5b57\u6bcd\u987a\u5e8f\uff0c\u901a\u8fc7\u76f8\u90bb\u7684\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u6784\u6210\uff0c\u5176\u4e2d\u201c\u76f8\u90bb\u201d\u5355\u5143\u683c\u662f\u90a3\u4e9b\u6c34\u5e73\u76f8\u90bb\u6216\u5782\u76f4\u76f8\u90bb\u7684\u5355\u5143\u683c\u3002\u540c\u4e00\u4e2a\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u4e0d\u5141\u8bb8\u88ab\u91cd\u590d\u4f7f\u7528\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.leetcode.com\/uploads\/2020\/11\/04\/word2.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>board = [['A','B','C','E'],['S','F','C','S'],['A','D','E','E']], word = \"ABCCED\"<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>true<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>dfs,\u5bfb\u627e\u6240\u6709\u53ef\u80fd\u8d77\u70b9\u8fdb\u884cdfs,\u5c06\u7ed3\u679c\u8fdb\u884c\u6216\u64cd\u4f5c\uff0c\u5373\u6709\u4e00\u6761\u8def\u901a\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def exist(self, board: List&#91;List&#91;str]], word: str) -&gt; bool:\n        row,col=len(board),len(board&#91;0])\n        def dfs(r:int,c:int,k:int)-&gt;bool:\n            if board&#91;r]&#91;c]!=word&#91;k]:\n                return False\n            if k==len(word)-1:\n                return True\n            board&#91;r]&#91;c]=''\n            for x,y in (r,c-1),(r+1,c),(r,c+1),(r-1,c):\n                if 0&lt;=x&lt;row and 0&lt;=y&lt;col :\n                    if dfs(x,y,k+1):\n                        return True\n            board&#91;r]&#91;c]=word&#91;k]\n            return False\n        ans=False\n        for i in range(row):\n            for j in range(col):\n                if board&#91;i]&#91;j]==word&#91;0]:\n                    ans=ans or dfs(i,j,0)\n        return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">75.<a href=\"https:\/\/leetcode.cn\/problems\/daily-temperatures\/\" target=\"_blank\"  rel=\"nofollow\" >\u6bcf\u65e5\u6e29\u5ea6<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>temperatures<\/code>&nbsp;\uff0c\u8868\u793a\u6bcf\u5929\u7684\u6e29\u5ea6\uff0c\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4&nbsp;<code>answer<\/code>&nbsp;\uff0c\u5176\u4e2d&nbsp;<code>answer[i]<\/code>&nbsp;\u662f\u6307\u5bf9\u4e8e\u7b2c&nbsp;<code>i<\/code>&nbsp;\u5929\uff0c\u4e0b\u4e00\u4e2a\u66f4\u9ad8\u6e29\u5ea6\u51fa\u73b0\u5728\u51e0\u5929\u540e\u3002\u5982\u679c\u6c14\u6e29\u5728\u8fd9\u4e4b\u540e\u90fd\u4e0d\u4f1a\u5347\u9ad8\uff0c\u8bf7\u5728\u8be5\u4f4d\u7f6e\u7528&nbsp;<code>0<\/code>&nbsp;\u6765\u4ee3\u66ff\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165:<\/strong> temperatures = [73,74,75,71,69,72,76,73]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa:<\/strong>&nbsp;[1,1,4,2,1,1,0,0]<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u5355\u8c03\u6808\uff0c\u52a8\u6001\u7ef4\u62a4\u8fd1\u671f\u6700\u5927\u503c.\u4ece\u5de6\u5411\u53f3\u601d\u8003\u4e0d\u77e5\u9053\u4e0b\u4e00\u4e2a\u66f4\u5927\u503c\u5728\u54ea\uff0c\u4ece\u53f3\u5411\u5de6\u601d\u8003\u53ef\u4ee5\u83b7\u53d6\u8fd9\u4e9b\u4fe1\u606f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def dailyTemperatures(self, temperatures: List&#91;int]) -&gt; List&#91;int]:\n        n = len(temperatures)\n        ans = &#91;0] * n\n        st = &#91;]\n        for i in range(n - 1, -1, -1):\n            t = temperatures&#91;i]\n            #\u65b0\u7684\u6570\u5927\u4e8e\u8001\u7684\u6570\uff0c\u8001\u6570\u5f39\u51fa\n            while st and t &gt;= temperatures&#91;st&#91;-1]]:\n                st.pop()\n            #\u5f39\u51fa\u540e\u6570\u6808\u4e0d\u4e3a\u7a7a\uff0c&#91;-1]\u4f4d\u7f6e\u4e0a\u5373\u4e3a\u6700\u8fd1\u7684\u5927\u4e8e\u672c\u8eab\u7684\u6570\n            if st:\n                ans&#91;i] = st&#91;-1] - i\n            #\u5c06\u65b0\u6570\u5165\u6808\n            st.append(i)\n        return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">76.<a href=\"https:\/\/leetcode.cn\/problems\/jump-game-ii\/\" target=\"_blank\"  rel=\"nofollow\" >\u8df3\u8dc3\u6e38\u620f II<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;<code>n<\/code>&nbsp;\u7684&nbsp;<strong>0 \u7d22\u5f15<\/strong>\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>\u3002\u521d\u59cb\u4f4d\u7f6e\u5728\u4e0b\u6807 0\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e2a\u5143\u7d20&nbsp;<code>nums[i]<\/code>&nbsp;\u8868\u793a\u4ece\u7d22\u5f15&nbsp;<code>i<\/code>&nbsp;\u5411\u540e\u8df3\u8f6c\u7684\u6700\u5927\u957f\u5ea6\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5982\u679c\u4f60\u5728\u7d22\u5f15&nbsp;<code>i<\/code>&nbsp;\u5904\uff0c\u4f60\u53ef\u4ee5\u8df3\u8f6c\u5230\u4efb\u610f&nbsp;<code>(i + j)<\/code>&nbsp;\u5904\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>0 &lt;= j &lt;= nums[i]<\/code>&nbsp;\u4e14<\/li>\n\n\n\n<li><code>i + j &lt; n<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u8fd4\u56de\u5230\u8fbe&nbsp;<code>n - 1<\/code>&nbsp;\u7684\u6700\u5c0f\u8df3\u8dc3\u6b21\u6570\u3002\u6d4b\u8bd5\u7528\u4f8b\u4fdd\u8bc1\u53ef\u4ee5\u5230\u8fbe&nbsp;<code>n - 1<\/code>\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165:<\/strong> nums = [2,3,1,1,4]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa:<\/strong> 2<\/li>\n\n\n\n<li><strong>\u89e3\u91ca:<\/strong> \u8df3\u5230\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u7684\u6700\u5c0f\u8df3\u8dc3\u6570\u662f <code>2<\/code>\u3002<\/li>\n\n\n\n<li>&nbsp;    \u4ece\u4e0b\u6807\u4e3a 0 \u8df3\u5230\u4e0b\u6807\u4e3a 1 \u7684\u4f4d\u7f6e\uff0c\u8df3&nbsp;<code>1<\/code>&nbsp;\u6b65\uff0c\u7136\u540e\u8df3&nbsp;<code>3<\/code>&nbsp;\u6b65\u5230\u8fbe\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>cur\u8bb0\u5f55N\u6b65\u80fd\u5230\u8fbe\u7684\u6700\u8fdc\u8ddd\u79bb\uff0cright\u8bb0\u5f55\u4ee5\u4e0a\u4e00\u6b65\u548c\u8fd9\u4e00\u6b65\u4e4b\u95f4\u7684\u67d0\u70b9\u4e3a\u8d77\u70b9\u80fd\u5230\u8fbe\u7684\u6700\u8fdc\u8ddd\u79bb\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def jump(self, nums: List&#91;int]) -&gt; int:\n        cur=0\n        right=0\n        step=0\n        for i in range(len(nums)-1):\n            right=max(i+nums&#91;i],right)\n            if i==cur:\n                cur=right\n                step+=1\n        return step<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">77.<a href=\"https:\/\/leetcode.cn\/problems\/partition-labels\/\" target=\"_blank\"  rel=\"nofollow\" >\u5212\u5206\u5b57\u6bcd\u533a\u95f4<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>&nbsp;\u3002\u6211\u4eec\u8981\u628a\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5212\u5206\u4e3a\u5c3d\u53ef\u80fd\u591a\u7684\u7247\u6bb5\uff0c\u540c\u4e00\u5b57\u6bcd\u6700\u591a\u51fa\u73b0\u5728\u4e00\u4e2a\u7247\u6bb5\u4e2d\u3002\u4f8b\u5982\uff0c\u5b57\u7b26\u4e32&nbsp;<code>\"ababcc\"<\/code>&nbsp;\u80fd\u591f\u88ab\u5206\u4e3a&nbsp;<code>[\"abab\", \"cc\"]<\/code>\uff0c\u4f46\u7c7b\u4f3c&nbsp;<code>[\"aba\", \"bcc\"]<\/code>&nbsp;\u6216&nbsp;<code>[\"ab\", \"ab\", \"cc\"]<\/code>&nbsp;\u7684\u5212\u5206\u662f\u975e\u6cd5\u7684\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\uff0c\u5212\u5206\u7ed3\u679c\u9700\u8981\u6ee1\u8db3\uff1a\u5c06\u6240\u6709\u5212\u5206\u7ed3\u679c\u6309\u987a\u5e8f\u8fde\u63a5\uff0c\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u4ecd\u7136\u662f&nbsp;<code>s<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u6bcf\u4e2a\u5b57\u7b26\u4e32\u7247\u6bb5\u7684\u957f\u5ea6\u7684\u5217\u8868\u3002<strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>s = \"ababcbacadefegdehijhklij\"<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>[9,7,8]<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong><\/li>\n\n\n\n<li>\u5212\u5206\u7ed3\u679c\u4e3a \"ababcbaca\"\u3001\"defegde\"\u3001\"hijhklij\" \u3002<\/li>\n\n\n\n<li>\u6bcf\u4e2a\u5b57\u6bcd\u6700\u591a\u51fa\u73b0\u5728\u4e00\u4e2a\u7247\u6bb5\u4e2d\u3002<\/li>\n\n\n\n<li>\u50cf \"ababcbacadefegde\", \"hijhklij\" \u8fd9\u6837\u7684\u5212\u5206\u662f\u9519\u8bef\u7684\uff0c\u56e0\u4e3a\u5212\u5206\u7684\u7247\u6bb5\u6570\u8f83\u5c11\u3002 <\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u5c06\u5206\u6bb5\u5185\u6240\u6709\u5b57\u6bcd\u7b2c\u4e00\u4e2a\u51fa\u73b0\u7684\u4f4d\u7f6e\u4e0e\u6700\u540e\u4e00\u4e2a\u51fa\u73b0\u7684\u4f4d\u7f6e\u5408\u5e76\u5373\u4e3a\u4e00\u4e2a\u6ee1\u8db3\u8981\u6c42\u7684\u5206\u6bb5\uff0c\u8d77\u59cb\u4f4d\u7f6e\u4ece\u8d77\u70b9\u5f00\u59cb\u5373\u53ef\uff0c\u7ec8\u70b9\u9700\u8981\u77e5\u9053\u5b57\u6bcd\u6700\u7ec8\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0c\u56e0\u6b64\u5148\u904d\u5386\u4e00\u6b21\u8bb0\u5f55\u6bcf\u4e2a\u5b57\u6bcd\u7684\u7ec8\u70b9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def partitionLabels(self, s: str) -&gt; List&#91;int]:\n        hs={}\n        start=end=0\n        ans=&#91;]\n        for i,c in enumerate(s):\n            hs&#91;c]=i\n        for i,c in enumerate(s):\n            end=max(end,hs&#91;c])\n            if i==end:\n                ans.append(end-start+1)\n                start=end+1\n                end=end+1\n        return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">78.<a href=\"https:\/\/leetcode.cn\/problems\/perfect-squares\/\" target=\"_blank\"  rel=\"nofollow\" >\u5b8c\u5168\u5e73\u65b9\u6570<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570&nbsp;<code>n<\/code>&nbsp;\uff0c\u8fd4\u56de&nbsp;<em>\u548c\u4e3a&nbsp;<code>n<\/code>&nbsp;\u7684\u5b8c\u5168\u5e73\u65b9\u6570\u7684\u6700\u5c11\u6570\u91cf<\/em>&nbsp;\u3002<\/p>\n\n\n\n<p><strong>\u5b8c\u5168\u5e73\u65b9\u6570<\/strong>&nbsp;\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u5176\u503c\u7b49\u4e8e\u53e6\u4e00\u4e2a\u6574\u6570\u7684\u5e73\u65b9\uff1b\u6362\u53e5\u8bdd\u8bf4\uff0c\u5176\u503c\u7b49\u4e8e\u4e00\u4e2a\u6574\u6570\u81ea\u4e58\u7684\u79ef\u3002\u4f8b\u5982\uff0c<code>1<\/code>\u3001<code>4<\/code>\u3001<code>9<\/code>&nbsp;\u548c&nbsp;<code>16<\/code>&nbsp;\u90fd\u662f\u5b8c\u5168\u5e73\u65b9\u6570\uff0c\u800c&nbsp;<code>3<\/code>&nbsp;\u548c&nbsp;<code>11<\/code>&nbsp;\u4e0d\u662f\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>n = <code>12<\/code><\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>3 <\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong><code>12 = 4 + 4 + 4<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u9012\u5f52\u65b9\u6cd5\uff0c\u9009\u6216\u4e0d\u9009<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@cache\ndef dfs(x:int,left:int)-&gt;bool:\n    if x==0 :\n        #left\u4e0d\u4e3a0\u5219\u9519\u8bef\uff0c\u7528inf\u5ffd\u7565\u6b64\u8def\u5f84\n        return inf if left else 0\n    if x*x&gt;left:\n        return dfs(x-1,left)\n    return min(dfs(x-1,left),dfs(x,left-x*x)+1)\nclass Solution:\n\n    def numSquares(self, n: int) -&gt; int:\n\n        return dfs(isqrt(n),n)<\/code><\/pre>\n\n\n\n<p>\u9012\u63a8<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>N = 10000 #n\u5c0f\u4e8e\u7b49\u4e8e10000\uff0c\u9898\u76ee\u6761\u4ef6\nf = &#91;&#91;0] * (N + 1) for _ in range(isqrt(N) + 1)]\nf&#91;0] = &#91;0] + &#91;inf] * N\nfor i in range(1, len(f)):\n    for j in range(N + 1):\n        if j &lt; i * i:\n            f&#91;i]&#91;j] = f&#91;i - 1]&#91;j]  # \u53ea\u80fd\u4e0d\u9009\n        else:\n            f&#91;i]&#91;j] = min(f&#91;i - 1]&#91;j], f&#91;i]&#91;j - i * i] + 1)  # \u4e0d\u9009 vs \u9009\n\nclass Solution:\n    def numSquares(self, n: int) -&gt; int:\n        return f&#91;isqrt(n)]&#91;n]  # \u4e5f\u53ef\u4ee5\u5199 f&#91;-1]&#91;n]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">79.<a href=\"https:\/\/leetcode.cn\/problems\/coin-change\/\" target=\"_blank\"  rel=\"nofollow\" >&nbsp;\u96f6\u94b1\u5151\u6362<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>coins<\/code>&nbsp;\uff0c\u8868\u793a\u4e0d\u540c\u9762\u989d\u7684\u786c\u5e01\uff1b\u4ee5\u53ca\u4e00\u4e2a\u6574\u6570&nbsp;<code>amount<\/code>&nbsp;\uff0c\u8868\u793a\u603b\u91d1\u989d\u3002<\/p>\n\n\n\n<p>\u8ba1\u7b97\u5e76\u8fd4\u56de\u53ef\u4ee5\u51d1\u6210\u603b\u91d1\u989d\u6240\u9700\u7684&nbsp;<strong>\u6700\u5c11\u7684\u786c\u5e01\u4e2a\u6570<\/strong>&nbsp;\u3002\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u4e00\u79cd\u786c\u5e01\u7ec4\u5408\u80fd\u7ec4\u6210\u603b\u91d1\u989d\uff0c\u8fd4\u56de&nbsp;<code>-1<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6bcf\u79cd\u786c\u5e01\u7684\u6570\u91cf\u662f\u65e0\u9650\u7684\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>coins = <code>[1, 2, 5]<\/code>, amount = <code>11<\/code><\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong><code>3<\/code> <\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong>11 = 5 + 5 + 1<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u9012\u5f52\uff0c\u9009\u6216\u4e0d\u9009<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def coinChange(self, coins: List&#91;int], amount: int) -&gt; int:\n        coins_sort=sorted(coins)\n        n=len(coins)\n        def dfs(x:int,left:int)-&gt;int:\n            if x==-1:\n                return inf if left else 0\n            if left&lt;coins_sort&#91;x]:\n                return dfs(x-1,left)\n            return min(dfs(x-1,left),dfs(x,left-coins_sort&#91;x])+1)\n        ans=dfs(n-1,amount)\n        return ans if ans&lt;inf else -1<\/code><\/pre>\n\n\n\n<p>\u9012\u63a8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def coinChange(self, coins: List&#91;int], amount: int) -&gt; int:\n        n = len(coins)\n        f = &#91;&#91;inf] * (amount + 1) for _ in range(n + 1)]\n        f&#91;0]&#91;0] = 0\n        for i, x in enumerate(coins):\n            for c in range(amount + 1):\n                if c &lt; x:  #c&lt;x\uff0c\u4e0d\u53d6\u5e01\n                    f&#91;i + 1]&#91;c] = f&#91;i]&#91;c]\n                else:     #c&gt;=x\uff0c\u53d6\u5e01\n                    f&#91;i + 1]&#91;c] = min(f&#91;i]&#91;c], f&#91;i + 1]&#91;c - x] + 1)\n        ans = f&#91;n]&#91;amount]\n        return ans if ans &lt; inf else -1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">80.<a href=\"https:\/\/leetcode.cn\/problems\/word-break\/\" target=\"_blank\"  rel=\"nofollow\" >\u5355\u8bcd\u62c6\u5206<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>&nbsp;\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868&nbsp;<code>wordDict<\/code>&nbsp;\u4f5c\u4e3a\u5b57\u5178\u3002\u5982\u679c\u53ef\u4ee5\u5229\u7528\u5b57\u5178\u4e2d\u51fa\u73b0\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u5355\u8bcd\u62fc\u63a5\u51fa&nbsp;<code>s<\/code>&nbsp;\u5219\u8fd4\u56de&nbsp;<code>true<\/code>\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u4e0d\u8981\u6c42\u5b57\u5178\u4e2d\u51fa\u73b0\u7684\u5355\u8bcd\u5168\u90e8\u90fd\u4f7f\u7528\uff0c\u5e76\u4e14\u5b57\u5178\u4e2d\u7684\u5355\u8bcd\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165:<\/strong> s = \"leetcode\", wordDict = [\"leet\", \"code\"]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa:<\/strong> true<\/li>\n\n\n\n<li><strong>\u89e3\u91ca:<\/strong> \u8fd4\u56de true \u56e0\u4e3a \"leetcode\" \u53ef\u4ee5\u7531 \"leet\" \u548c \"code\" \u62fc\u63a5\u6210\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u4ece\u540e\u5411\u524d\uff0c\u5339\u914d\u5207\u7247\u662f\u5426\u5728\u8bcd\u8868\u4e2d\uff0c\u5728\u7684\u8bdd\u5219\u5c06\u5269\u4f59\u90e8\u5206\u8fdb\u884c\u9012\u5f52<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def wordBreak(self, s: str, wordDict: List&#91;str]) -&gt; bool:\n        max_len=max(map(len,wordDict))\n        words=set(wordDict)\n        @cache\n        def dfs(i:int)-&gt;bool:\n            if i==0:\n                return True\n            for j in range(i-1,max(i-max_len-1,-1),-1):\n                if s&#91;j:i] in words and dfs(j):\n                    return True\n            return False\n        return dfs(len(s))<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">81.<a href=\"https:\/\/leetcode.cn\/problems\/longest-increasing-subsequence\/\" target=\"_blank\"  rel=\"nofollow\" >\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u627e\u5230\u5176\u4e2d\u6700\u957f\u4e25\u683c\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<p><strong>\u5b50\u5e8f\u5217&nbsp;<\/strong>\u662f\u7531\u6570\u7ec4\u6d3e\u751f\u800c\u6765\u7684\u5e8f\u5217\uff0c\u5220\u9664\uff08\u6216\u4e0d\u5220\u9664\uff09\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u800c\u4e0d\u6539\u53d8\u5176\u4f59\u5143\u7d20\u7684\u987a\u5e8f\u3002\u4f8b\u5982\uff0c<code>[3,6,2,7]<\/code>&nbsp;\u662f\u6570\u7ec4&nbsp;<code>[0,3,1,6,2,2,7]<\/code>&nbsp;\u7684\u5b50\u5e8f\u5217\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>nums = [10,9,2,5,3,7,101,18]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>4<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong>\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u662f [2,3,7,101]\uff0c\u56e0\u6b64\u957f\u5ea6\u4e3a 4 \u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u4ece\u7b2c0\u4e2a\u5143\u7d20\u5f00\u59cb\u9010\u6b65\u5411\u53f3\u5c55\u5f00\u904d\u5386\u533a\u95f4\uff0c\u6bcf\u6b21\u6269\u5c55\u4e00\u4e2a\u5143\u7d20\uff0c\u904d\u5386\u524d\u5e8f\u5206\u522b\u5f53\u4f5c\u4e0a\u4e00\u8df3\u8d77\u70b9\uff0c\u5224\u65ad\u662f\u5426\u9012\u589e\uff0c\u662f\u5219\u8fdb\u884c\u4e00\u6b21\u6bd4\u8f83\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def lengthOfLIS(self, nums: List&#91;int]) -&gt; int:\n        f=&#91;0]*len(nums)\n        for i,x in enumerate(nums):\n            for j,y in enumerate(nums&#91;:i]):\n                if x&gt;y:\n                    f&#91;i]=max(f&#91;i],f&#91;j])\n            f&#91;i]+=1\n        return max(f)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">82.<a href=\"https:\/\/leetcode.cn\/problems\/maximum-product-subarray\/\" target=\"_blank\"  rel=\"nofollow\" >\u4e58\u79ef\u6700\u5927\u5b50\u6570\u7ec4<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u8bf7\u4f60\u627e\u51fa\u6570\u7ec4\u4e2d\u4e58\u79ef\u6700\u5927\u7684\u975e\u7a7a\u8fde\u7eed&nbsp;\u5b50\u6570\u7ec4\uff08\u8be5\u5b50\u6570\u7ec4\u4e2d\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u6570\u5b57\uff09\uff0c\u5e76\u8fd4\u56de\u8be5\u5b50\u6570\u7ec4\u6240\u5bf9\u5e94\u7684\u4e58\u79ef\u3002<\/p>\n\n\n\n<p>\u6d4b\u8bd5\u7528\u4f8b\u7684\u7b54\u6848\u662f\u4e00\u4e2a&nbsp;<strong>32-\u4f4d<\/strong>&nbsp;\u6574\u6570\u3002<\/p>\n\n\n\n<p><strong>\u8bf7\u6ce8\u610f<\/strong>\uff0c\u4e00\u4e2a\u53ea\u5305\u542b\u4e00\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\u7684\u4e58\u79ef\u662f\u8fd9\u4e2a\u5143\u7d20\u7684\u503c\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165:<\/strong> nums = [2,3,-2,4]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa:<\/strong> <code>6<\/code><\/li>\n\n\n\n<li><strong>\u89e3\u91ca:<\/strong>&nbsp;\u5b50\u6570\u7ec4 [2,3] \u6709\u6700\u5927\u4e58\u79ef 6\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u6700\u5927\u6700\u5c0f\u90fd\u8bb0\u5f55\u5e76\u8fd0\u7b97\uff0c\u907f\u514d\u7b26\u53f7\u5f71\u54cd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def maxProduct(self, nums: List&#91;int]) -&gt; int:\n        n=len(nums)\n        f_min=&#91;0]*n\n        f_max=&#91;0]*n \n        f_max&#91;0]=f_min&#91;0]=nums&#91;0]\n        for i in range(1,n):\n            x=nums&#91;i]\n            f_min&#91;i]=min(f_max&#91;i-1]*x,f_min&#91;i-1]*x,x)\n            f_max&#91;i]=max(f_max&#91;i-1]*x,f_min&#91;i-1]*x,x)\n        return max(f_max)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">83.<a href=\"https:\/\/leetcode.cn\/problems\/palindrome-partitioning\/\" target=\"_blank\"  rel=\"nofollow\" >\u5206\u5272\u56de\u6587\u4e32<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>\uff0c\u8bf7\u4f60\u5c06<em>&nbsp;<\/em><code>s<\/code><em>&nbsp;<\/em>\u5206\u5272\u6210\u4e00\u4e9b&nbsp;\u5b50\u4e32\uff0c\u4f7f\u6bcf\u4e2a\u5b50\u4e32\u90fd\u662f&nbsp;<strong>\u56de\u6587\u4e32<\/strong>&nbsp;\u3002\u8fd4\u56de&nbsp;<code>s<\/code>&nbsp;\u6240\u6709\u53ef\u80fd\u7684\u5206\u5272\u65b9\u6848\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>s = \"aab\"<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>[[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u6bcf\u4e24\u4e2a\u5b57\u7b26\u4e4b\u95f4\u5747\u53ef\u9009\u62e9\u65ad\u5f00\u6216\u4e0d\u65ad\u5f00\uff0c\u904d\u5386\u6240\u6709\u9009\u62e9\u5e76\u5224\u65ad\u662f\u5426\u56de\u6587<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def partition(self, s: str) -&gt; List&#91;List&#91;str]]:\n        n=len(s)\n        ans=&#91;]\n        path=&#91;]\n\n        def dfs(i:int,start:int)-&gt;None:\n            if i==n:\n                ans.append(path&#91;:])\n                return\n            if i&lt;n-1:\n                dfs(i+1,start)\n            t=s&#91;start:i+1]\n            if t==t&#91;::-1]:\n                path.append(t)\n                dfs(i+1,i+1)\n                path.pop()\n        dfs(0,0)\n        return ans<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">84.<a href=\"https:\/\/leetcode.cn\/problems\/find-minimum-in-rotated-sorted-array\/\" target=\"_blank\"  rel=\"nofollow\" >\u5bfb\u627e\u65cb\u8f6c\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c<\/a><\/h2>\n\n\n\n<p>\u5df2\u77e5\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;<code>n<\/code>&nbsp;\u7684\u6570\u7ec4\uff0c\u9884\u5148\u6309\u7167\u5347\u5e8f\u6392\u5217\uff0c\u7ecf\u7531&nbsp;<code>1<\/code>&nbsp;\u5230&nbsp;<code>n<\/code>&nbsp;\u6b21&nbsp;<strong>\u65cb\u8f6c<\/strong>&nbsp;\u540e\uff0c\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u539f\u6570\u7ec4&nbsp;<code>nums = [0,1,2,4,5,6,7]<\/code>&nbsp;\u5728\u53d8\u5316\u540e\u53ef\u80fd\u5f97\u5230\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u82e5\u65cb\u8f6c&nbsp;<code>4<\/code>&nbsp;\u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230&nbsp;<code>[4,5,6,7,0,1,2]<\/code><\/li>\n\n\n\n<li>\u82e5\u65cb\u8f6c&nbsp;<code>7<\/code>&nbsp;\u6b21\uff0c\u5219\u53ef\u4ee5\u5f97\u5230&nbsp;<code>[0,1,2,4,5,6,7]<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u6ce8\u610f\uff0c\u6570\u7ec4&nbsp;<code>[a[0], a[1], a[2], ..., a[n-1]]<\/code>&nbsp;<strong>\u65cb\u8f6c\u4e00\u6b21<\/strong>&nbsp;\u7684\u7ed3\u679c\u4e3a\u6570\u7ec4&nbsp;<code>[a[n-1], a[0], a[1], a[2], ..., a[n-2]]<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5143\u7d20\u503c&nbsp;<strong>\u4e92\u4e0d\u76f8\u540c<\/strong>&nbsp;\u7684\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u5b83\u539f\u6765\u662f\u4e00\u4e2a\u5347\u5e8f\u6392\u5217\u7684\u6570\u7ec4\uff0c\u5e76\u6309\u4e0a\u8ff0\u60c5\u5f62\u8fdb\u884c\u4e86\u591a\u6b21\u65cb\u8f6c\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u6570\u7ec4\u4e2d\u7684&nbsp;<strong>\u6700\u5c0f\u5143\u7d20<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u4f60\u5fc5\u987b\u8bbe\u8ba1\u4e00\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a&nbsp;<code>O(log n)<\/code>&nbsp;\u7684\u7b97\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>nums = [3,4,5,1,2]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>1<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong>\u539f\u6570\u7ec4\u4e3a [1,2,3,4,5] \uff0c\u65cb\u8f6c 3 \u6b21\u5f97\u5230\u8f93\u5165\u6570\u7ec4\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u65cb\u8f6c\u524d\u662f\u6709\u5e8f\u7684\uff0c\u540c\u6837\u53ef\u4ee5\u91c7\u7528\u4e8c\u5206\u67e5\u627e\uff0c<\/p>\n\n\n\n<p>\u82e5nums[mid]&lt;nums[-1],\u5219\u6700\u5c0f\u503c\u4f4d\u4e8e[left,mid],\u53cd\u4e4b\u4f4d\u4e8e[mid,right]<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def findMin(self, nums: List&#91;int]) -&gt; int:\n        left,right=0,len(nums)-1\n        while left&lt;=right:\n            mid=(left+right)\/\/2\n            if nums&#91;mid]&lt;nums&#91;-1]:\n                right=mid-1\n            else:\n                left=mid+1\n        i= min(left,len(nums)-1) #\u6700\u5c0f\u503c\u4f4d\u4e8e\u6700\u540e\u65f6left\u4f1a\u8d8a\u754c\uff0c\u53d6min\u9632\u6b62\u8d8a\u754c\n        return nums&#91;i]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">85.<a href=\"https:\/\/leetcode.cn\/problems\/median-of-two-sorted-arrays\/\" target=\"_blank\"  rel=\"nofollow\" >&nbsp;\u5bfb\u627e\u4e24\u4e2a\u6b63\u5e8f\u6570\u7ec4\u7684\u4e2d\u4f4d\u6570<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e24\u4e2a\u5927\u5c0f\u5206\u522b\u4e3a&nbsp;<code>m<\/code>&nbsp;\u548c&nbsp;<code>n<\/code>&nbsp;\u7684\u6b63\u5e8f\uff08\u4ece\u5c0f\u5230\u5927\uff09\u6570\u7ec4&nbsp;<code>nums1<\/code>&nbsp;\u548c&nbsp;<code>nums2<\/code>\u3002\u8bf7\u4f60\u627e\u51fa\u5e76\u8fd4\u56de\u8fd9\u4e24\u4e2a\u6b63\u5e8f\u6570\u7ec4\u7684&nbsp;<strong>\u4e2d\u4f4d\u6570<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5e94\u8be5\u4e3a&nbsp;<code>O(log (m+n))<\/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>nums1 = [1,3], nums2 = [2]\n<strong>\u8f93\u51fa\uff1a<\/strong>2.00000\n<strong>\u89e3\u91ca\uff1a<\/strong>\u5408\u5e76\u6570\u7ec4 = [1,2,3] \uff0c\u4e2d\u4f4d\u6570 2<\/pre>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u6682\u65f6\u7ed9\u51faO\uff08(m+n)\/2\uff09\u7684\u65b9\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def findMedianSortedArrays(self, nums1: List&#91;int], nums2: List&#91;int]) -&gt; float:\n        m, n = len(nums1), len(nums2)\n        total_length = m + n\n        \n        # 1. \u786e\u5b9a\u9700\u8981\u6536\u96c6\u7684\u76ee\u6807\u4f4d\u7f6e\uff08\u7d22\u5f15\u4ece0\u5f00\u59cb\uff09\n        if total_length % 2 == 1:\n            # \u5947\u6570\uff1a\u53ea\u53d6\u4e2d\u95f41\u4e2a\n            target_indices = &#91;total_length \/\/ 2]\n        else:\n            # \u5076\u6570\uff1a\u53d6\u4e2d\u95f42\u4e2a\n            target_indices = &#91;total_length \/\/ 2 - 1, total_length \/\/ 2]\n        \n        l1 = l2 = 0  # \u53cc\u6307\u9488\n        current_index = 0  # \u5f53\u524d\u904d\u5386\u5230\u7684\u5168\u5c40\u7d22\u5f15\n        result = &#91;]  # \u5b58\u50a8\u76ee\u6807\u4f4d\u7f6e\u7684\u5143\u7d20\n        \n        # 2. \u904d\u5386\u76f4\u5230\u6536\u96c6\u5b8c\u6240\u6709\u76ee\u6807\u5143\u7d20\uff08\u6838\u5fc3\u4f18\u5316\uff1a\u63d0\u524d\u7ec8\u6b62\uff09\n        while len(result) &lt; len(target_indices):\n            # \u5b89\u5168\u83b7\u53d6\u5f53\u524d\u8981\u53d6\u7684\u5143\u7d20\uff08\u4f18\u5148\u5904\u7406\u8fb9\u754c\uff09\n            if l1 &gt;= m:\n                # nums1\u5df2\u904d\u5386\u5b8c\uff0c\u53ea\u53d6nums2\n                val = nums2&#91;l2]\n                l2 += 1\n            elif l2 &gt;= n:\n                # nums2\u5df2\u904d\u5386\u5b8c\uff0c\u53ea\u53d6nums1\n                val = nums1&#91;l1]\n                l1 += 1\n            else:\n                # \u53d6\u4e24\u4e2a\u6570\u7ec4\u4e2d\u8f83\u5c0f\u7684\u5143\u7d20\n                if nums1&#91;l1] &lt; nums2&#91;l2]:\n                    val = nums1&#91;l1]\n                    l1 += 1\n                else:\n                    val = nums2&#91;l2]\n                    l2 += 1\n            \n            # 3. \u5982\u679c\u5f53\u524d\u7d22\u5f15\u662f\u76ee\u6807\u7d22\u5f15\uff0c\u6536\u96c6\u5143\u7d20\n            if current_index in target_indices:\n                result.append(val)\n            \n            current_index += 1\n        \n        # 4. \u8ba1\u7b97\u4e2d\u4f4d\u6570\n        return sum(result) \/ len(result)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">86.<a href=\"https:\/\/leetcode.cn\/problems\/partition-equal-subset-sum\/\" target=\"_blank\"  rel=\"nofollow\" >\u5206\u5272\u7b49\u548c\u5b50\u96c6<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a&nbsp;<strong>\u53ea\u5305\u542b\u6b63\u6574\u6570&nbsp;<\/strong>\u7684&nbsp;<strong>\u975e\u7a7a&nbsp;<\/strong>\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\u3002\u8bf7\u4f60\u5224\u65ad\u662f\u5426\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u6570\u7ec4\u5206\u5272\u6210\u4e24\u4e2a\u5b50\u96c6\uff0c\u4f7f\u5f97\u4e24\u4e2a\u5b50\u96c6\u7684\u5143\u7d20\u548c\u76f8\u7b49\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>nums = [1,5,11,5]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>true<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong>\u6570\u7ec4\u53ef\u4ee5\u5206\u5272\u6210 [1, 5, 5] \u548c [11] \u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u9009\u6216\u4e0d\u9009\uff0c\u9012\u5f52<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def canPartition(self, nums: List&#91;int]) -&gt; bool:\n        n_sum=sum(nums)\n        n=len(nums)\n        @cache\n        def dfs(i:int,j:int)-&gt;bool:\n            if i&lt;0:\n                return j==0\n            if j&lt;nums&#91;i]:\n                return dfs(i-1,j)\n            return dfs(i-1,j-nums&#91;i]) or dfs(i-1,j)\n        return n_sum%2==0 and dfs(n-1,n_sum\/\/2)<\/code><\/pre>\n\n\n\n<p>\u9012\u63a8\u5f62\u5f0f\uff0c\u601d\u60f3\u4e5f\u4e3a\u9009\u6216\u4e0d\u9009\uff0c\u904d\u5386n\u4e2a\u8282\u70b9\u80fd\u9009\u5230\u7684\u7ed3\u679c\u7f6etrue<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def canPartition(self, nums: List&#91;int]) -&gt; bool:\n        s = sum(nums)\n        if s % 2:\n            return False\n        s \/\/= 2  # \u6ce8\u610f\u8fd9\u91cc\u628a s \u51cf\u534a\u4e86\n        n = len(nums)\n        f = &#91;&#91;False] * (s + 1) for _ in range(n + 1)]\n        f&#91;0]&#91;0] = True\n        for i, x in enumerate(nums):\n            for j in range(s + 1):\n                f&#91;i + 1]&#91;j] = j &gt;= x and f&#91;i]&#91;j - x] or f&#91;i]&#91;j]\n        return f&#91;n]&#91;s]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">87.<a href=\"https:\/\/leetcode.cn\/problems\/unique-paths\/\" target=\"_blank\"  rel=\"nofollow\" >\u4e0d\u540c\u8def\u5f84<\/a><\/h2>\n\n\n\n<p>\u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a&nbsp;<code>m x n<\/code><em>&nbsp;<\/em>\u7f51\u683c\u7684\u5de6\u4e0a\u89d2 \uff08\u8d77\u59cb\u70b9\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cStart\u201d \uff09\u3002<\/p>\n\n\n\n<p>\u673a\u5668\u4eba\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002\u673a\u5668\u4eba\u8bd5\u56fe\u8fbe\u5230\u7f51\u683c\u7684\u53f3\u4e0b\u89d2\uff08\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a \u201cFinish\u201d \uff09\u3002<\/p>\n\n\n\n<p>\u95ee\u603b\u5171\u6709\u591a\u5c11\u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1f<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic.leetcode.cn\/1697422740-adxmsI-image.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>m = 3, n = 7<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>28<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>m[i][j]=m[i-1][j]+m[i][j-1]<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def uniquePaths(self, m: int, n: int) -&gt; int:\n        mp=&#91;&#91;1]*n for _ in range(m)]\n        for i in range(1,m):\n            for j in range(1,n):\n                mp&#91;i]&#91;j]=mp&#91;i-1]&#91;j]+mp&#91;i]&#91;j-1]\n        return mp&#91;m-1]&#91;n-1]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">88.<a href=\"https:\/\/leetcode.cn\/problems\/minimum-path-sum\/\" target=\"_blank\"  rel=\"nofollow\" >\u6700\u5c0f\u8def\u5f84\u548c<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u975e\u8d1f\u6574\u6570\u7684&nbsp;<code><em>m<\/em>&nbsp;x&nbsp;<em>n<\/em><\/code>&nbsp;\u7f51\u683c&nbsp;<code>grid<\/code>&nbsp;\uff0c\u8bf7\u627e\u51fa\u4e00\u6761\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u7684\u8def\u5f84\uff0c\u4f7f\u5f97\u8def\u5f84\u4e0a\u7684\u6570\u5b57\u603b\u548c\u4e3a\u6700\u5c0f\u3002<\/p>\n\n\n\n<p><strong>\u8bf4\u660e\uff1a<\/strong>\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.leetcode.com\/uploads\/2020\/11\/05\/minpath.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>grid = [[1,3,1],[1,5,1],[4,2,1]]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>7<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong>\u56e0\u4e3a\u8def\u5f84 1\u21923\u21921\u21921\u21921 \u7684\u603b\u548c\u6700\u5c0f\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>m[i][j]+=min(m[i-1][j],m[i][j-1])<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def minPathSum(self, grid: List&#91;List&#91;int]]) -&gt; int:\n        row,col = len(grid),len(grid&#91;0])\n        for i in range(1,row):\n            grid&#91;i]&#91;0]+=grid&#91;i-1]&#91;0]\n        for i in range(1,col):\n            grid&#91;0]&#91;i]+=grid&#91;0]&#91;i-1]\n        for i in range(1,row):\n            for j in range(1,col):\n                grid&#91;i]&#91;j]+=min(grid&#91;i-1]&#91;j],grid&#91;i]&#91;j-1])\n        return grid&#91;row-1]&#91;col-1]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">89.<a href=\"https:\/\/leetcode.cn\/problems\/longest-palindromic-substring\/\" target=\"_blank\"  rel=\"nofollow\" >\u6700\u957f\u56de\u6587\u5b50\u4e32<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>\uff0c\u627e\u5230&nbsp;<code>s<\/code>&nbsp;\u4e2d\u6700\u957f\u7684&nbsp;\u56de\u6587&nbsp;\u5b50\u4e32\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>s = \"babad\"<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>\"bab\"<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong>\"aba\" \u540c\u6837\u662f\u7b26\u5408\u9898\u610f\u7684\u7b54\u6848\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u904d\u5386\u5b57\u7b26\u4e32\uff0c\u4ee5\u5b57\u7b26\u4e3a\u4e2d\u5fc3\u5411\u4e24\u4fa7\u6269\u5c55\uff0c\u5bfb\u627e\u6700\u957f\u56de\u6587<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def longestPalindrome(self, s: str) -&gt; str:\n        n=len(s)\n        ans_left=ans_right=0\n        for i in range(2*n-1):\n            l,r=i\/\/2,(i+1)\/\/2\n            while l&gt;=0 and r&lt;n and s&#91;l]==s&#91;r]:\n                l-=1\n                r+=1\n            if r-l-1&gt;ans_right-ans_left:\n                ans_left,ans_right=l+1,r \n        return s&#91;ans_left:ans_right]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">90.<a href=\"https:\/\/leetcode.cn\/problems\/longest-common-subsequence\/\" target=\"_blank\"  rel=\"nofollow\" >\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>text1<\/code>&nbsp;\u548c&nbsp;<code>text2<\/code>\uff0c\u8fd4\u56de\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u957f&nbsp;<strong>\u516c\u5171\u5b50\u5e8f\u5217<\/strong>&nbsp;\u7684\u957f\u5ea6\u3002\u5982\u679c\u4e0d\u5b58\u5728&nbsp;<strong>\u516c\u5171\u5b50\u5e8f\u5217<\/strong>&nbsp;\uff0c\u8fd4\u56de&nbsp;<code>0<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684&nbsp;<strong>\u5b50\u5e8f\u5217<\/strong><em>&nbsp;<\/em>\u662f\u6307\u8fd9\u6837\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff1a\u5b83\u662f\u7531\u539f\u5b57\u7b26\u4e32\u5728\u4e0d\u6539\u53d8\u5b57\u7b26\u7684\u76f8\u5bf9\u987a\u5e8f\u7684\u60c5\u51b5\u4e0b\u5220\u9664\u67d0\u4e9b\u5b57\u7b26\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\u4efb\u4f55\u5b57\u7b26\uff09\u540e\u7ec4\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5982\uff0c<code>\"ace\"<\/code>&nbsp;\u662f&nbsp;<code>\"abcde\"<\/code>&nbsp;\u7684\u5b50\u5e8f\u5217\uff0c\u4f46&nbsp;<code>\"aec\"<\/code>&nbsp;\u4e0d\u662f&nbsp;<code>\"abcde\"<\/code>&nbsp;\u7684\u5b50\u5e8f\u5217\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684&nbsp;<strong>\u516c\u5171\u5b50\u5e8f\u5217<\/strong>&nbsp;\u662f\u8fd9\u4e24\u4e2a\u5b57\u7b26\u4e32\u6240\u5171\u540c\u62e5\u6709\u7684\u5b50\u5e8f\u5217\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>text1 = \"abcde\", text2 = \"ace\" <\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>3  <\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong>\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217\u662f \"ace\" \uff0c\u5b83\u7684\u957f\u5ea6\u4e3a 3 \u3002<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u628atext1\u4f5c\u4e3a\u7eb5\u8f74\uff0ctext2\u4f5c\u4e3a\u6a2a\u8f74\uff0c\u6328\u4e2a\u5bf9\u6bd4\uff0c\u5b57\u6bcd\u76f8\u540c\u5219mp[i][j]=mp[i-1][j-1]+1,\u4e0d\u540c\u5219\u76f4\u63a5\u7ee7\u627fmp[i][j]=max(mp[i-1][j],mp[i][j-1])<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def longestCommonSubsequence(self, text1: str, text2: str) -&gt; int:\n        m,n=len(text1),len(text2)\n        mp=&#91;&#91;0]*(n+1) for _ in range(m+1)]\n        for i in range(1,m+1):\n            for j in range(1,n+1):\n                if text1&#91;i-1]==text2&#91;j-1]:\n                    mp&#91;i]&#91;j]=mp&#91;i-1]&#91;j-1]+1\n                else:\n                    mp&#91;i]&#91;j]=max(mp&#91;i-1]&#91;j],mp&#91;i]&#91;j-1])\n        return mp&#91;m]&#91;n]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">91.<a href=\"https:\/\/leetcode.cn\/problems\/edit-distance\/\" target=\"_blank\"  rel=\"nofollow\" >\u7f16\u8f91\u8ddd\u79bb<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e24\u4e2a\u5355\u8bcd&nbsp;<code>word1<\/code>&nbsp;\u548c&nbsp;<code>word2<\/code>\uff0c&nbsp;<em>\u8bf7\u8fd4\u56de\u5c06&nbsp;<code>word1<\/code>&nbsp;\u8f6c\u6362\u6210&nbsp;<code>word2<\/code>&nbsp;\u6240\u4f7f\u7528\u7684\u6700\u5c11\u64cd\u4f5c\u6570<\/em>&nbsp;&nbsp;\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5bf9\u4e00\u4e2a\u5355\u8bcd\u8fdb\u884c\u5982\u4e0b\u4e09\u79cd\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26<\/li>\n\n\n\n<li>\u5220\u9664\u4e00\u4e2a\u5b57\u7b26<\/li>\n\n\n\n<li>\u66ff\u6362\u4e00\u4e2a\u5b57\u7b26<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>word1 = \"horse\", word2 = \"ros\"<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>3<\/li>\n\n\n\n<li><strong>\u89e3\u91ca\uff1a<\/strong><\/li>\n\n\n\n<li>horse -&gt; rorse (\u5c06 'h' \u66ff\u6362\u4e3a 'r')<\/li>\n\n\n\n<li>rorse -&gt; rose (\u5220\u9664 'r')<\/li>\n\n\n\n<li>rose -&gt; ros (\u5220\u9664 'e')<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>word1\u4f5c\u4e3a\u7eb5\u8f74\uff0cword2\u4f5c\u4e3a\u6a2a\u8f74\uff0c\u521d\u59cb\u5316\u7b2c\u4e00\u884c\uff0c\u503c\u4e3arange(len(s)+1),\u542b\u4e49\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e00\u76f4\u8df3\u8fc7\u76f4\u5230\u7b2c\u4e00\u4e2a\u9996\u5b57\u6bcd\u5339\u914d\u4e0a\u9700\u8981\u64cd\u4f5c\u7684\u6b21\u6570\uff0c\u7b2c\u4e00\u5217\u5728\u904d\u5386\u65f6\u521d\u59cb\u5316.\u904d\u5386\u65f6\u9047\u5230\u4e24\u79cd\u60c5\u51b5\uff0c\u5339\u914d\u4e0e\u4e0d\u5339\u914d\uff0c\u5339\u914d\u5219\u90fd\u5411\u540e\u79fb\u4e00\u4e2a\u5143\u7d20\uff0c\u4e0d\u5339\u914d\u5219\u9009\u62e9\u5220\u9664\uff08\u63d2\u5165\uff09\u6216\u66ff\u6362<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def minDistance(self, word1: str, word2: str) -&gt; int:\n        n,m =len(word1),len(word2)\n        f=&#91;&#91;0]*(m+1) for _ in range(n+1)]\n        f&#91;0]=list(range(m+1))\n        for i,x in enumerate(word1):\n            f&#91;i+1]&#91;0]=i+1\n            for j,y in enumerate(word2):\n                #\u76f8\u7b49\u5219\u8fdb\u4e0b\u4e00\u6b65\uff0c\u4e0d\u7b49\u5219A\u63d2\u5165\u6216B\u63d2\u5165\u6216\u66ff\u6362\n                f&#91;i+1]&#91;j+1]=f&#91;i]&#91;j] if x==y else min(f&#91;i]&#91;j+1],f&#91;i+1]&#91;j],f&#91;i]&#91;j])+1\n        return f&#91;n]&#91;m]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">92.<a href=\"https:\/\/leetcode.cn\/problems\/single-number\/\" target=\"_blank\"  rel=\"nofollow\" >\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570\u5b57<\/a><\/h2>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a&nbsp;<strong>\u975e\u7a7a<\/strong>&nbsp;\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u9664\u4e86\u67d0\u4e2a\u5143\u7d20\u53ea\u51fa\u73b0\u4e00\u6b21\u4ee5\u5916\uff0c\u5176\u4f59\u6bcf\u4e2a\u5143\u7d20\u5747\u51fa\u73b0\u4e24\u6b21\u3002\u627e\u51fa\u90a3\u4e2a\u53ea\u51fa\u73b0\u4e86\u4e00\u6b21\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u4f60\u5fc5\u987b\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u7b97\u6cd5\u6765\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u4e14\u8be5\u7b97\u6cd5\u53ea\u4f7f\u7528\u5e38\u91cf\u989d\u5916\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1 \uff1a<\/strong><\/p>\n\n\n\n<p><strong>\u8f93\u5165\uff1a<\/strong>nums = [2,2,1]<\/p>\n\n\n\n<p><strong>\u8f93\u51fa\uff1a<\/strong>1<\/p>\n\n\n\n<p>\u89e3:<\/p>\n\n\n\n<p>\u5229\u7528\u5f02\u6216\u8fd0\u7b97 a^a=0\u7684\u7279\u6027\uff0c\u5c06\u51fa\u73b0\u4e24\u6b21\u7684\u6570\u6e05\u9664\uff0c\u5269\u4e0b\u7ed3\u679c\u5373\u4e3a\u53ea\u51fa\u73b0\u4e00\u6b21\u7684\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def singleNumber(self, nums: List&#91;int]) -&gt; int:\n        res=0\n        for i in nums:\n            res ^=i \n        return res<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">93.<a href=\"https:\/\/leetcode.cn\/problems\/majority-element\/\" target=\"_blank\"  rel=\"nofollow\" >\u591a\u6570\u5143\u7d20<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5927\u5c0f\u4e3a&nbsp;<code>n<\/code><em>&nbsp;<\/em>\u7684\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u8fd4\u56de\u5176\u4e2d\u7684\u591a\u6570\u5143\u7d20\u3002\u591a\u6570\u5143\u7d20\u662f\u6307\u5728\u6570\u7ec4\u4e2d\u51fa\u73b0\u6b21\u6570&nbsp;<strong>\u5927\u4e8e<\/strong>&nbsp;<code>\u230a n\/2 \u230b<\/code>&nbsp;\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u5047\u8bbe\u6570\u7ec4\u662f\u975e\u7a7a\u7684\uff0c\u5e76\u4e14\u7ed9\u5b9a\u7684\u6570\u7ec4\u603b\u662f\u5b58\u5728\u591a\u6570\u5143\u7d20\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1\uff1a<\/strong><\/p>\n\n\n\n<p><strong>\u8f93\u5165\uff1a<\/strong>nums = [3,2,3]\n<strong>\u8f93\u51fa\uff1a<\/strong>3<\/p>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u6469\u5c14\u6295\u7968\u6cd5\uff0c\u7c7b\u4f3c\u6253\u64c2\u53f0\u4e00\u6362\u4e00\uff0c\u591a\u6570\u5143\u7d20\u8d85\u8fc7\u534a\u6570\uff0c\u4e00\u6362\u4e00\u6700\u540e\u5269\u4e0b\u7684\u5143\u7d20\u4e00\u5b9a\u662f\u5b83<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def majorityElement(self, nums: List&#91;int]) -&gt; int:\n        cnt=1\n        last=nums&#91;0]\n        for i in range(1,len(nums)):\n            if cnt==0:\n                last=nums&#91;i]\n                cnt+=1\n                continue\n            if nums&#91;i]!=last:\n                cnt-=1\n            else:\n                cnt+=1\n        return last<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">94.<a href=\"https:\/\/leetcode.cn\/problems\/sort-colors\/\" target=\"_blank\"  rel=\"nofollow\" >\u989c\u8272\u5206\u7c7b<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\u3001\u5171&nbsp;<code>n<\/code><em>&nbsp;<\/em>\u4e2a\u5143\u7d20\u7684\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c<strong><a href=\"https:\/\/baike.baidu.com\/item\/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u539f\u5730<\/a>&nbsp;<\/strong>\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\uff0c\u4f7f\u5f97\u76f8\u540c\u989c\u8272\u7684\u5143\u7d20\u76f8\u90bb\uff0c\u5e76\u6309\u7167\u7ea2\u8272\u3001\u767d\u8272\u3001\u84dd\u8272\u987a\u5e8f\u6392\u5217\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528\u6574\u6570&nbsp;<code>0<\/code>\u3001&nbsp;<code>1<\/code>&nbsp;\u548c&nbsp;<code>2<\/code>&nbsp;\u5206\u522b\u8868\u793a\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\u3002<\/p>\n\n\n\n<p>\u5fc5\u987b\u5728\u4e0d\u4f7f\u7528\u5e93\u5185\u7f6e\u7684 sort \u51fd\u6570\u7684\u60c5\u51b5\u4e0b\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>nums = [2,0,2,1,1,0]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>[0,0,1,1,2,2]<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u4e09\u6307\u9488\uff0c\u4e2d\u95f4\u6307\u9488\u6307\u54110\uff0c\u5219\u8ddf\u5de6\u6307\u9488\u4ea4\u6362\uff0c\u6307\u54112\u5219\u8ddf\u53f3\u6307\u9488\u4ea4\u6362<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def sortColors(self, nums: List&#91;int]) -&gt; None:\n        \"\"\"\n        Do not return anything, modify nums in-place instead.\n        \"\"\"\n        # \u5206\u522b\u6307\u54110\uff0c1\uff0c2\u533a\u57df\n        low, mid, high = 0, 0, len(nums) - 1\n        # mid\u662f\u6d3b\u52a8\u6307\u9488\n        while mid &lt;= high:\n            if nums&#91;mid] == 0:  # \u8bf4\u660e\u8981\u4ea4\u6362\u52300\u533a\n                nums&#91;low], nums&#91;mid] = nums&#91;mid], nums&#91;low]\n                low += 1\n                mid += 1\n            elif nums&#91;mid] == 1:  # \u6b63\u597d\n                mid += 1\n            else:  # \u5426\u5219\u4ea4\u6362\u52302\u533a\n                nums&#91;mid], nums&#91;high] = nums&#91;high], nums&#91;mid]\n                high -= 1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">95.<a href=\"https:\/\/leetcode.cn\/problems\/next-permutation\/\" target=\"_blank\"  rel=\"nofollow\" >\u4e0b\u4e00\u4e2a\u6392\u5217<\/a><\/h2>\n\n\n\n<p>\u6574\u6570\u6570\u7ec4\u7684\u4e00\u4e2a&nbsp;<strong>\u6392\u5217<\/strong>&nbsp; \u5c31\u662f\u5c06\u5176\u6240\u6709\u6210\u5458\u4ee5\u5e8f\u5217\u6216\u7ebf\u6027\u987a\u5e8f\u6392\u5217\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5982\uff0c<code>arr = [1,2,3]<\/code>&nbsp;\uff0c\u4ee5\u4e0b\u8fd9\u4e9b\u90fd\u53ef\u4ee5\u89c6\u4f5c&nbsp;<code>arr<\/code>&nbsp;\u7684\u6392\u5217\uff1a<code>[1,2,3]<\/code>\u3001<code>[1,3,2]<\/code>\u3001<code>[3,1,2]<\/code>\u3001<code>[2,3,1]<\/code>&nbsp;\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u6574\u6570\u6570\u7ec4\u7684&nbsp;<strong>\u4e0b\u4e00\u4e2a\u6392\u5217<\/strong>&nbsp;\u662f\u6307\u5176\u6574\u6570\u7684\u4e0b\u4e00\u4e2a\u5b57\u5178\u5e8f\u66f4\u5927\u7684\u6392\u5217\u3002\u66f4\u6b63\u5f0f\u5730\uff0c\u5982\u679c\u6570\u7ec4\u7684\u6240\u6709\u6392\u5217\u6839\u636e\u5176\u5b57\u5178\u987a\u5e8f\u4ece\u5c0f\u5230\u5927\u6392\u5217\u5728\u4e00\u4e2a\u5bb9\u5668\u4e2d\uff0c\u90a3\u4e48\u6570\u7ec4\u7684&nbsp;<strong>\u4e0b\u4e00\u4e2a\u6392\u5217<\/strong>&nbsp;\u5c31\u662f\u5728\u8fd9\u4e2a\u6709\u5e8f\u5bb9\u5668\u4e2d\u6392\u5728\u5b83\u540e\u9762\u7684\u90a3\u4e2a\u6392\u5217\u3002\u5982\u679c\u4e0d\u5b58\u5728\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u6392\u5217\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u7ec4\u5fc5\u987b\u91cd\u6392\u4e3a\u5b57\u5178\u5e8f\u6700\u5c0f\u7684\u6392\u5217\uff08\u5373\uff0c\u5176\u5143\u7d20\u6309\u5347\u5e8f\u6392\u5217\uff09\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5982\uff0c<code>arr = [1,2,3]<\/code>&nbsp;\u7684\u4e0b\u4e00\u4e2a\u6392\u5217\u662f&nbsp;<code>[1,3,2]<\/code>&nbsp;\u3002<\/li>\n\n\n\n<li>\u7c7b\u4f3c\u5730\uff0c<code>arr = [2,3,1]<\/code>&nbsp;\u7684\u4e0b\u4e00\u4e2a\u6392\u5217\u662f&nbsp;<code>[3,1,2]<\/code>&nbsp;\u3002<\/li>\n\n\n\n<li>\u800c&nbsp;<code>arr = [3,2,1]<\/code>&nbsp;\u7684\u4e0b\u4e00\u4e2a\u6392\u5217\u662f&nbsp;<code>[1,2,3]<\/code>&nbsp;\uff0c\u56e0\u4e3a&nbsp;<code>[3,2,1]<\/code>&nbsp;\u4e0d\u5b58\u5728\u4e00\u4e2a\u5b57\u5178\u5e8f\u66f4\u5927\u7684\u6392\u5217\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u627e\u51fa&nbsp;<code>nums<\/code>&nbsp;\u7684\u4e0b\u4e00\u4e2a\u6392\u5217\u3002<\/p>\n\n\n\n<p>\u5fc5\u987b<strong><a href=\"https:\/\/baike.baidu.com\/item\/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >&nbsp;\u539f\u5730&nbsp;<\/a><\/strong>\u4fee\u6539\uff0c\u53ea\u5141\u8bb8\u4f7f\u7528\u989d\u5916\u5e38\u6570\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>nums = [1,2,3]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>[1,3,2]<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u4ece\u53f3\u5f80\u5de6\u627e\u5230\u53f3\u8fb9\u5b58\u5728\u6bd4\u5de6\u8fb9\u5927\u7684\u6570\uff0c\u601d\u8def\u4e3a\u5224\u65ad\u5de6\u8fb9\u7684\u6570\u662f\u5426\u6bd4\u8d77\u76f8\u90bb\u7684\u53f3\u8fb9\u7684\u6570\u5c0f\uff0c\u82e5\u662f\uff0c\u5219\u627e\u5230<\/p>\n\n\n\n<p>\u5728\u4ece\u53f3\u5f80\u5de6\u5bfb\u627e\u7b2c\u4e00\u4e2a\u6bd4\u6b64\u6570\u5927\u7684\u6570\uff0c\u4ea4\u6362\u4f4d\u7f6e<\/p>\n\n\n\n<p>\u518d\u5c06left+1\u81f3\u7ed3\u5c3e\u8fdb\u884c\u53cd\u8f6c\uff0c\u5c06\u539f\u672c\u7684\u964d\u5e8f\u8f6c\u4e3a\u5347\u5e8f\uff0c\u5f97\u5230\u6700\u5c0f\u5c3e\u90e8<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def nextPermutation(self, nums: List&#91;int]) -&gt; None:\n        \"\"\"\n        Do not return anything, modify nums in-place instead.\n        \"\"\"\n        n=len(nums)\n        i=n-2\n        while i&gt;=0 and nums&#91;i]&gt;=nums&#91;i+1]:\n            i-=1\n        if i&gt;=0:\n            j=n-1\n            while nums&#91;j]&lt;=nums&#91;i]:\n                j-=1\n            nums&#91;i],nums&#91;j]=nums&#91;j],nums&#91;i]\n        left,right = i+1,n-1\n        while left&lt;right:\n            nums&#91;left],nums&#91;right]=nums&#91;right],nums&#91;left]\n            left+=1\n            right-=1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">96.<a href=\"https:\/\/leetcode.cn\/problems\/find-the-duplicate-number\/\" target=\"_blank\"  rel=\"nofollow\" >\u5bfb\u627e\u91cd\u590d\u6570<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b&nbsp;<code>n + 1<\/code>&nbsp;\u4e2a\u6574\u6570\u7684\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u5176\u6570\u5b57\u90fd\u5728&nbsp;<code>[1, n]<\/code>&nbsp;\u8303\u56f4\u5185\uff08\u5305\u62ec&nbsp;<code>1<\/code>&nbsp;\u548c&nbsp;<code>n<\/code>\uff09\uff0c\u53ef\u77e5\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u91cd\u590d\u7684\u6574\u6570\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe&nbsp;<code>nums<\/code>&nbsp;\u53ea\u6709&nbsp;<strong>\u4e00\u4e2a\u91cd\u590d\u7684\u6574\u6570<\/strong>&nbsp;\uff0c\u8fd4\u56de&nbsp;<strong>\u8fd9\u4e2a\u91cd\u590d\u7684\u6570<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u4f60\u8bbe\u8ba1\u7684\u89e3\u51b3\u65b9\u6848\u5fc5\u987b&nbsp;<strong>\u4e0d\u4fee\u6539<\/strong>&nbsp;\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\u4e14\u53ea\u7528\u5e38\u91cf\u7ea7&nbsp;<code>O(1)<\/code>&nbsp;\u7684\u989d\u5916\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>nums = [1,3,4,2,2]<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>2<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u6cd51\uff1a<\/p>\n\n\n\n<p>\u628a\u5143\u7d20\u6362\u5230\u5bf9\u7684\u4f4d\u7f6e\u4e0a\uff0c\u4f7f\u5f97nums[i]=nums[nums[i]-1]<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def findDuplicate(self, nums: List&#91;int]) -&gt; int:\n        n = len(nums)\n        # \u904d\u5386\u6bcf\u4e2a\u4f4d\u7f6e\uff0c\u5c06\u5143\u7d20\u5f52\u4f4d\n        for i in range(n):\n            # \u5f53\u5f53\u524d\u5143\u7d20\u4e0d\u5728\u81ea\u5df1\u7684\u6b63\u786e\u4f4d\u7f6e\u65f6\uff0c\u624d\u5904\u7406\n            while nums&#91;i] != i + 1:\n                # \u53d6\u51fa\u5f53\u524d\u5143\u7d20\u7684\u503c\n                val = nums&#91;i]\n                # \u68c0\u67e5\uff1aval\u7684\u6b63\u786e\u4f4d\u7f6e\uff08val-1\uff09\u662f\u5426\u5df2\u6709\u76f8\u540c\u503c \u2192 \u8bf4\u660eval\u91cd\u590d\n                if nums&#91;val - 1] == val:\n                    return val\n                # \u5426\u5219\uff0c\u5c06val\u4ea4\u6362\u5230\u6b63\u786e\u4f4d\u7f6e\n                nums&#91;i], nums&#91;val - 1] = nums&#91;val - 1], nums&#91;i]<\/code><\/pre>\n\n\n\n<p>\u6cd52\uff1a<\/p>\n\n\n\n<p>\u628a\u5217\u8868\u62bd\u8c61\u6210\u94fe\u8868\uff0c\u627e\u73af \u5217\u8868nums[i]\u7684\u4e0b\u4e00\u8df3\u662fnums[nums[i]]<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4ee3\u7801\u903b\u8f91\u540c 142. \u73af\u5f62\u94fe\u8868 II\nclass Solution:\n    def findDuplicate(self, nums: List&#91;int]) -&gt; int:\n        slow = fast = 0  # 0 \u4e00\u5b9a\u4e0d\u5728\u73af\u4e0a\uff0c\u9002\u5408\u4f5c\u4e3a\u8d77\u70b9\n        while True:\n            slow = nums&#91;slow]  # \u7b49\u4ef7\u4e8e slow = slow.next\n            fast = nums&#91;nums&#91;fast]]  # \u7b49\u4ef7\u4e8e fast = fast.next.next\n            if fast == slow:  # \u5feb\u6162\u6307\u9488\u79fb\u52a8\u5230\u540c\u4e00\u4e2a\u8282\u70b9\n                break\n\n        head = 0  # \u518d\u7528\u4e00\u4e2a\u6307\u9488\uff0c\u4ece\u8d77\u70b9\u51fa\u53d1\n        while slow != head:\n            slow = nums&#91;slow]\n            head = nums&#91;head]\n        return slow  # \u5165\u73af\u53e3\u5373\u91cd\u590d\u5143\u7d20<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">97.<a href=\"https:\/\/leetcode.cn\/problems\/add-strings\/\" target=\"_blank\"  rel=\"nofollow\" >\u5b57\u7b26\u4e32\u76f8\u52a0<\/a><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u975e\u8d1f\u6574\u6570&nbsp;<code>num1<\/code>&nbsp;\u548c<code>num2<\/code>&nbsp;\uff0c\u8ba1\u7b97\u5b83\u4eec\u7684\u548c\u5e76\u540c\u6837\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8fd4\u56de\u3002<\/p>\n\n\n\n<p>\u4f60\u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u5167\u5efa\u7684\u7528\u4e8e\u5904\u7406\u5927\u6574\u6570\u7684\u5e93\uff08\u6bd4\u5982&nbsp;<code>BigInteger<\/code>\uff09\uff0c&nbsp;\u4e5f\u4e0d\u80fd\u76f4\u63a5\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u5f62\u5f0f\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\uff1a<\/strong>num1 = \"11\", num2 = \"123\"<\/li>\n\n\n\n<li><strong>\u8f93\u51fa\uff1a<\/strong>\"134\"<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\uff1a<\/p>\n\n\n\n<p>\u6a21\u62df\u52a0\u6cd5\u8ba1\u7b97\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def addStrings(self, num1: str, num2: str) -> str:\n        res=\"\"\n        #\u6307\u5411\u4e24\u6570\u4e2a\u4f4d\n        i,j,carry=len(num1)-1,len(num2)-1,0\n        while i>=0 or j>=0:\n        #\u6570\u4e0d\u5b58\u5728\u88650\n            n1=int(num1&#91;i]) if i >=0 else 0\n            n2=int(num2&#91;j]) if j >=0 else 0\n            tmp=n1+n2+carry\n            carry=tmp\/\/10\n            res=str(tmp%10)+res\n            i,j=i-1,j-1\n        #\u8fdb\u4f4d\u8fd8\u5b58\u5728\u5219\u52a0\u4e00\u4f4d1\n        return '1'+res if carry else res<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>65.\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408 \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57&nbsp;2-9&nbsp;\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u6240\u6709\u5b83\u80fd\u8868\u793a\u7684\u5b57\u6bcd\u7ec4\u5408\u3002\u7b54\u6848\u53ef\u4ee5\u6309&#038;nbs &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-167","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2) - Sunsyblog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100\u5237\u9898\u7b14\u8bb02\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2) - Sunsyblog\" \/>\n<meta property=\"og:description\" content=\"65.\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408 \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57&nbsp;2-9&nbsp;\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u6240\u6709\u5b83\u80fd\u8868\u793a\u7684\u5b57\u6bcd\u7ec4\u5408\u3002\u7b54\u6848\u53ef\u4ee5\u6309&amp;nbs ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100\u5237\u9898\u7b14\u8bb02\/\" \/>\n<meta property=\"og:site_name\" content=\"Sunsyblog\" \/>\n<meta property=\"article:published_time\" content=\"2026-03-16T09:56:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-25T08:03:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png\" \/>\n<meta name=\"author\" content=\"Sunsy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sunsy\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/\",\"url\":\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/\",\"name\":\"LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2) - Sunsyblog\",\"isPartOf\":{\"@id\":\"https:\/\/sunsyblog.cn\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png\",\"datePublished\":\"2026-03-16T09:56:40+00:00\",\"dateModified\":\"2026-03-25T08:03:35+00:00\",\"author\":{\"@id\":\"https:\/\/sunsyblog.cn\/#\/schema\/person\/3cf3cdc8731e915f0d9f81cb9ca82712\"},\"breadcrumb\":{\"@id\":\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#primaryimage\",\"url\":\"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png\",\"contentUrl\":\"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/sunsyblog.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/sunsyblog.cn\/#website\",\"url\":\"https:\/\/sunsyblog.cn\/\",\"name\":\"Sunsyblog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/sunsyblog.cn\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/sunsyblog.cn\/#\/schema\/person\/3cf3cdc8731e915f0d9f81cb9ca82712\",\"name\":\"Sunsy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/sunsyblog.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/weavatar.com\/avatar\/aa5b790f3d479fd400751c087e871f92282767b1cbde478b4961ba50ad307f05?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/weavatar.com\/avatar\/aa5b790f3d479fd400751c087e871f92282767b1cbde478b4961ba50ad307f05?s=96&d=mm&r=g\",\"caption\":\"Sunsy\"},\"sameAs\":[\"http:\/\/124.220.189.177\"],\"url\":\"https:\/\/sunsyblog.cn\/index.php\/author\/sunsy\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2) - Sunsyblog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100\u5237\u9898\u7b14\u8bb02\/","og_locale":"zh_CN","og_type":"article","og_title":"LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2) - Sunsyblog","og_description":"65.\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408 \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57&nbsp;2-9&nbsp;\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u6240\u6709\u5b83\u80fd\u8868\u793a\u7684\u5b57\u6bcd\u7ec4\u5408\u3002\u7b54\u6848\u53ef\u4ee5\u6309&nbs ...","og_url":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100\u5237\u9898\u7b14\u8bb02\/","og_site_name":"Sunsyblog","article_published_time":"2026-03-16T09:56:40+00:00","article_modified_time":"2026-03-25T08:03:35+00:00","og_image":[{"url":"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png","type":"","width":"","height":""}],"author":"Sunsy","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"Sunsy","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/","url":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/","name":"LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2) - Sunsyblog","isPartOf":{"@id":"https:\/\/sunsyblog.cn\/#website"},"primaryImageOfPage":{"@id":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#primaryimage"},"image":{"@id":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#primaryimage"},"thumbnailUrl":"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png","datePublished":"2026-03-16T09:56:40+00:00","dateModified":"2026-03-25T08:03:35+00:00","author":{"@id":"https:\/\/sunsyblog.cn\/#\/schema\/person\/3cf3cdc8731e915f0d9f81cb9ca82712"},"breadcrumb":{"@id":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#primaryimage","url":"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png","contentUrl":"https:\/\/pic.leetcode.cn\/1752723054-mfIHZs-image.png"},{"@type":"BreadcrumbList","@id":"https:\/\/sunsyblog.cn\/index.php\/2026\/03\/16\/leetcode-hot-100%e5%88%b7%e9%a2%98%e7%ac%94%e8%ae%b02\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/sunsyblog.cn\/"},{"@type":"ListItem","position":2,"name":"LeetCode Hot 100\u5237\u9898\u7b14\u8bb0(2)"}]},{"@type":"WebSite","@id":"https:\/\/sunsyblog.cn\/#website","url":"https:\/\/sunsyblog.cn\/","name":"Sunsyblog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sunsyblog.cn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/sunsyblog.cn\/#\/schema\/person\/3cf3cdc8731e915f0d9f81cb9ca82712","name":"Sunsy","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/sunsyblog.cn\/#\/schema\/person\/image\/","url":"https:\/\/weavatar.com\/avatar\/aa5b790f3d479fd400751c087e871f92282767b1cbde478b4961ba50ad307f05?s=96&d=mm&r=g","contentUrl":"https:\/\/weavatar.com\/avatar\/aa5b790f3d479fd400751c087e871f92282767b1cbde478b4961ba50ad307f05?s=96&d=mm&r=g","caption":"Sunsy"},"sameAs":["http:\/\/124.220.189.177"],"url":"https:\/\/sunsyblog.cn\/index.php\/author\/sunsy\/"}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Sunsy","author_link":"https:\/\/sunsyblog.cn\/index.php\/author\/sunsy\/"},"uagb_comment_info":0,"uagb_excerpt":"65.\u7535\u8bdd\u53f7\u7801\u7684\u5b57\u6bcd\u7ec4\u5408 \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57&nbsp;2-9&nbsp;\u7684\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u6240\u6709\u5b83\u80fd\u8868\u793a\u7684\u5b57\u6bcd\u7ec4\u5408&hellip;","_links":{"self":[{"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=167"}],"version-history":[{"count":11,"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":189,"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/167\/revisions\/189"}],"wp:attachment":[{"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunsyblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}