{"id":448,"date":"2023-09-11T17:39:23","date_gmt":"2023-09-11T09:39:23","guid":{"rendered":"http:\/\/lingbo.online\/?p=448"},"modified":"2023-09-22T23:09:27","modified_gmt":"2023-09-22T15:09:27","slug":"hw%e6%89%8b%e6%92%95%e6%b1%87%e6%80%bb","status":"publish","type":"post","link":"https:\/\/lingbo.online\/index.php\/uncategorized\/hw%e6%89%8b%e6%92%95%e6%b1%87%e6%80%bb\/","title":{"rendered":"HW\u624b\u6495\u6c47\u603b"},"content":{"rendered":"<h3>Leecode56. \u5408\u5e76\u533a\u95f4<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/merge-intervals\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/merge-intervals\/<\/a><br \/>\n\u4ee5\u6570\u7ec4 intervals \u8868\u793a\u82e5\u5e72\u4e2a\u533a\u95f4\u7684\u96c6\u5408\uff0c\u5176\u4e2d\u5355\u4e2a\u533a\u95f4\u4e3a intervals[i] = [starti, endi] \u3002\u8bf7\u4f60\u5408\u5e76\u6240\u6709\u91cd\u53e0\u7684\u533a\u95f4\uff0c\u5e76\u8fd4\u56de \u4e00\u4e2a\u4e0d\u91cd\u53e0\u7684\u533a\u95f4\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u9700\u6070\u597d\u8986\u76d6\u8f93\u5165\u4e2d\u7684\u6240\u6709\u533a\u95f4 \u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def merge(self, intervals: List[List[int]]) -&gt; List[List[int]]:\n        intervals.sort(key=lambda x:x[0])\n\n        merged=[]\n\n        for interval in intervals:\n            #\u5982\u679c\u5217\u8868\u4e3a\u7a7a\u6216\u5f53\u524d\u533a\u95f4\u4e0e\u4e0a\u4e00\u533a\u95f4\u4e0d\u91cd\u5408\uff0c\u76f4\u63a5\u6dfb\u52a0\n            if not merged or merged[-1][1]&lt;interval[0]:\n                merged.append(interval)\n            else:\n                merged[-1][1]=max(merged[-1][1],interval[1])\n\n        return merged<\/code><\/pre>\n<h3>Leecode168. Excel\u8868\u5217\u540d\u79f0<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/excel-sheet-column-title\/submissions\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/excel-sheet-column-title\/submissions\/<\/a><br \/>\n\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 columnNumber \uff0c\u8fd4\u56de\u5b83\u5728 Excel \u8868\u4e2d\u76f8\u5bf9\u5e94\u7684\u5217\u540d\u79f0\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def convertToTitle(self, columnNumber: int) -&gt; str:\n        result=&#039;&#039;\n        while columnNumber:\n            curr=columnNumber%26\n            result+=(chr(curr+64) if curr &gt;0 else &#039;Z&#039;)\n            columnNumber=columnNumber\/\/26\n            if curr==0:\n                columnNumber-=1\n        return &#039;&#039;.join(result[::-1])<\/code><\/pre>\n<h3>Leecode171. \u8868\u5217\u5e8f\u53f7<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/excel-sheet-column-number\/description\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/excel-sheet-column-number\/description\/<\/a><br \/>\n\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 columnTitle \uff0c\u8868\u793a Excel \u8868\u683c\u4e2d\u7684\u5217\u540d\u79f0\u3002\u8fd4\u56de \u8be5\u5217\u540d\u79f0\u5bf9\u5e94\u7684\u5217\u5e8f\u53f7\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def titleToNumber(self, columnTitle: str) -&gt; int:\n        result=0\n        count=0\n        for column in reversed(columnTitle):\n            result+=(ord(column)-ord(&#039;A&#039;)+1)*26**count\n            count+=1\n        return result<\/code><\/pre>\n<h3>Leecode5. \u6700\u957f\u56de\u6587\u5b50\u4e32<\/h3>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s\uff0c\u627e\u5230 s \u4e2d\u6700\u957f\u7684\u56de\u6587\u5b50\u4e32\u3002<\/p>\n<p>\u5982\u679c\u5b57\u7b26\u4e32\u7684\u53cd\u5e8f\u4e0e\u539f\u59cb\u5b57\u7b26\u4e32\u76f8\u540c\uff0c\u5219\u8be5\u5b57\u7b26\u4e32\u79f0\u4e3a\u56de\u6587\u5b57\u7b26\u4e32\u3002<\/p>\n<blockquote>\n<p>\u89e3\u9898\u601d\u8def\uff1a<br \/>\n\u679a\u4e3e\u6bcf\u4e2a\u70b9\u4f5c\u4e3a\u56de\u6587\u4e32\u7684\u4e2d\u5fc3\u70b9\uff0c\u5de6\u53f3\u6269\u6563\uff0c\u5982\u679c\u5de6\u8fb9\u7b49\u4e8e\u53f3\u8fb9\u5219\u7ee7\u7eed\u6269\u6563\u3002<br \/>\n\u6ce8\u610f\u8981\u8003\u8651\u56de\u6587\u4e32\u957f\u5ea6\u4e3a\u5947\u5076\u7684\u60c5\u51b5<\/p>\n<\/blockquote>\n<pre><code class=\"language-python\">class Solution:\n    def longestPalindrome(self, s: str) -&gt; str:\n        n=len(s)\n        res=&#039;&#039;\n\n        for i in range(n):\n        #\u5982\u679c\u6700\u957f\u56de\u6587\u5b50\u4e32\u7684\u957f\u5ea6\u4e3a\u5947\u6570\n            l,r=i-1,i+1\n            while l&gt;=0 and r&lt;n and s[l]==s[r]:\n                l,r=l-1,r+1\n            if (r-l-1&gt;len(res)):\n                res=s[l+1:r]\n\n            #\u5982\u679c\u6700\u957f\u56de\u6587\u5b50\u4e32\u7684\u957f\u5ea6\u4e3a\u5076\u6570\n            l,r=i,i+1\n            while l&gt;=0 and r&lt;n and s[l]==s[r]:\n                l,r=l-1,r+1\n            if (r-l-1&gt;len(res)):\n                res=s[l+1:r]\n        return res<\/code><\/pre>\n<h3>Leecode678. \u6709\u6548\u7684\u62ec\u53f7\u5b57\u7b26\u4e32<\/h3>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b\u4e09\u79cd\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u652f\u6301\u7684\u5b57\u7b26\u7c7b\u578b\u5206\u522b\u662f '('\u3001')' \u548c '*'\u3002\u8bf7\u4f60\u68c0\u9a8c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u6709\u6548\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u662f\u6709\u6548\u5b57\u7b26\u4e32\u8fd4\u56de true \u3002<\/p>\n<p>\u6709\u6548\u5b57\u7b26\u4e32\u7b26\u5408\u5982\u4e0b\u89c4\u5219\uff1a<\/p>\n<p>\u4efb\u4f55\u5de6\u62ec\u53f7 '(' \u5fc5\u987b\u6709\u76f8\u5e94\u7684\u53f3\u62ec\u53f7 ')'\u3002<br \/>\n\u4efb\u4f55\u53f3\u62ec\u53f7 ')' \u5fc5\u987b\u6709\u76f8\u5e94\u7684\u5de6\u62ec\u53f7 '(' \u3002<br \/>\n\u5de6\u62ec\u53f7 '(' \u5fc5\u987b\u5728\u5bf9\u5e94\u7684\u53f3\u62ec\u53f7\u4e4b\u524d ')'\u3002<br \/>\n'*' \u53ef\u4ee5\u88ab\u89c6\u4e3a\u5355\u4e2a\u53f3\u62ec\u53f7 ')' \uff0c\u6216\u5355\u4e2a\u5de6\u62ec\u53f7 '(' \uff0c\u6216\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002<br \/>\n\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u4e5f\u88ab\u89c6\u4e3a\u6709\u6548\u5b57\u7b26\u4e32\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def checkValidString(self, s: str) -&gt; bool:\n\n        # \u6b63\u5411\u904d\u5386\u6309\u7167\u4f18\u5148\u7ea7\u4f7f\u7528&quot;(&quot;\u548c&quot;*&quot;\u6d88\u9664&quot;)&quot;\n        stack = []\n        for w in s:\n            if w != &quot;)&quot;:\n                stack.append(w)\n            else:\n                if not stack:\n                    return False\n                m = len(stack)\n                i = -1\n                for j in range(m - 1, -1, -1):\n                    if stack[j] == &quot;(&quot;:\n                        i = j\n                        break\n                if i != -1:\n                    stack.pop(i)\n                else:\n                    stack.pop()\n\n        # \u53cd\u5411\u904d\u5386\u4f7f\u7528&quot;*&quot;\u6d88\u9664&quot;(&quot;\n        stack.reverse()\n        ans = []\n        for w in stack:\n            if w != &quot;(&quot;:\n                ans.append(w)\n            else:\n                if not ans:\n                    return False\n                ans.pop()\n        return True<\/code><\/pre>\n<h3>Leecode20. \u6709\u6548\u62ec\u53f7<\/h3>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u62ec '('\uff0c')'\uff0c'{'\uff0c'}'\uff0c'['\uff0c']' \u7684\u5b57\u7b26\u4e32 s \uff0c\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u6709\u6548\u3002<\/p>\n<p>\u6709\u6548\u5b57\u7b26\u4e32\u9700\u6ee1\u8db3\uff1a<\/p>\n<p>\u5de6\u62ec\u53f7\u5fc5\u987b\u7528\u76f8\u540c\u7c7b\u578b\u7684\u53f3\u62ec\u53f7\u95ed\u5408\u3002<br \/>\n\u5de6\u62ec\u53f7\u5fc5\u987b\u4ee5\u6b63\u786e\u7684\u987a\u5e8f\u95ed\u5408\u3002<br \/>\n\u6bcf\u4e2a\u53f3\u62ec\u53f7\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684\u76f8\u540c\u7c7b\u578b\u7684\u5de6\u62ec\u53f7\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def isValid(self, s: str) -&gt; bool:\n      dic = {&#039;)&#039;:&#039;(&#039;,&#039;]&#039;:&#039;[&#039;,&#039;}&#039;:&#039;{&#039;}\n\n      stack=[]\n\n      for w in s:\n        if stack and w in dic.keys():\n          if stack[-1]==dic[w]:\n            stack.pop()\n          else:\n            return False\n        else:\n          stack.append(w)\n      return not stack<\/code><\/pre>\n<h3>Leecode735. \u884c\u661f\u78b0\u649e<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/asteroid-collision\/description\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/asteroid-collision\/description\/<\/a><\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 asteroids\uff0c\u8868\u793a\u5728\u540c\u4e00\u884c\u7684\u884c\u661f\u3002<\/p>\n<p>\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u5176\u7edd\u5bf9\u503c\u8868\u793a\u884c\u661f\u7684\u5927\u5c0f\uff0c\u6b63\u8d1f\u8868\u793a\u884c\u661f\u7684\u79fb\u52a8\u65b9\u5411\uff08\u6b63\u8868\u793a\u5411\u53f3\u79fb\u52a8\uff0c\u8d1f\u8868\u793a\u5411\u5de6\u79fb\u52a8\uff09\u3002\u6bcf\u4e00\u9897\u884c\u661f\u4ee5\u76f8\u540c\u7684\u901f\u5ea6\u79fb\u52a8\u3002<\/p>\n<p>\u627e\u51fa\u78b0\u649e\u540e\u5269\u4e0b\u7684\u6240\u6709\u884c\u661f\u3002\u78b0\u649e\u89c4\u5219\uff1a\u4e24\u4e2a\u884c\u661f\u76f8\u4e92\u78b0\u649e\uff0c\u8f83\u5c0f\u7684\u884c\u661f\u4f1a\u7206\u70b8\u3002\u5982\u679c\u4e24\u9897\u884c\u661f\u5927\u5c0f\u76f8\u540c\uff0c\u5219\u4e24\u9897\u884c\u661f\u90fd\u4f1a\u7206\u70b8\u3002\u4e24\u9897\u79fb\u52a8\u65b9\u5411\u76f8\u540c\u7684\u884c\u661f\uff0c\u6c38\u8fdc\u4e0d\u4f1a\u53d1\u751f\u78b0\u649e\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def asteroidCollision(self, asteroids: List[int]) -&gt; List[int]:\n        stack=[]\n\n        for t in asteroids:\n            ok=True\n            while ok and stack and stack[-1]&gt;0 and t&lt;0:\n                a,b=stack[-1],-t\n\n                if a&lt;=b:\n                    stack.pop()\n                if a&gt;=b:\n                    ok=False\n            if ok:\n                stack.append(t)\n        return stack<\/code><\/pre>\n<h3>Offer54. \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u7b2ck\u5927\u8282\u70b9<\/h3>\n<p>\u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u8bf7\u627e\u51fa\u5176\u4e2d\u7b2c k \u5927\u7684\u8282\u70b9\u7684\u503c\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def kthLargest(self, root: TreeNode, k: int) -&gt; int:\n        result=[]\n        def dfs(root):\n            if not root:\n                return \n            dfs(root.left)\n            result.append(root.val)\n            dfs(root.right)\n\n        dfs(root)\n        return result[-k]<\/code><\/pre>\n<h3>LCR 060. \u524dk\u4e2a\u9ad8\u9891\u5143\u7d20<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/g5c51o\/description\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/g5c51o\/description\/<\/a><\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u6574\u6570 k \uff0c\u8bf7\u8fd4\u56de\u5176\u4e2d\u51fa\u73b0\u9891\u7387\u524d k \u9ad8\u7684\u5143\u7d20\u3002\u53ef\u4ee5\u6309<strong>\u4efb\u610f\u987a\u5e8f<\/strong>\u8fd4\u56de\u7b54\u6848\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def topKFrequent(self, nums: List[int], k: int) -&gt; List[int]:\n        dic={}\n\n        for i in nums:\n            if i not in dic:\n                dic[i]=1\n            else:\n                dic[i]+=1\n\n        dic=sorted(dic.items(),key=lambda x:x[1],reverse=True)\n        return [num[0] for num in dic][:k]<\/code><\/pre>\n<h3>Leecode.994 \u8150\u70c2\u7684\u6a58\u5b50<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/rotting-oranges\/description\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/rotting-oranges\/description\/<\/a><\/p>\n<p>\u5728\u7ed9\u5b9a\u7684 m x n \u7f51\u683c grid \u4e2d\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u53ef\u4ee5\u6709\u4ee5\u4e0b\u4e09\u4e2a\u503c\u4e4b\u4e00\uff1a<\/p>\n<p>\u503c 0 \u4ee3\u8868\u7a7a\u5355\u5143\u683c\uff1b<br \/>\n\u503c 1 \u4ee3\u8868\u65b0\u9c9c\u6a58\u5b50\uff1b<br \/>\n\u503c 2 \u4ee3\u8868\u8150\u70c2\u7684\u6a58\u5b50\u3002<br \/>\n\u6bcf\u5206\u949f\uff0c\u8150\u70c2\u7684\u6a58\u5b50 \u5468\u56f4 4 \u4e2a\u65b9\u5411\u4e0a\u76f8\u90bb \u7684\u65b0\u9c9c\u6a58\u5b50\u90fd\u4f1a\u8150\u70c2\u3002<\/p>\n<p>\u8fd4\u56de \u76f4\u5230\u5355\u5143\u683c\u4e2d\u6ca1\u6709\u65b0\u9c9c\u6a58\u5b50\u4e3a\u6b62\u6240\u5fc5\u987b\u7ecf\u8fc7\u7684\u6700\u5c0f\u5206\u949f\u6570\u3002\u5982\u679c\u4e0d\u53ef\u80fd\uff0c\u8fd4\u56de -1<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def orangesRotting(self, grid: List[List[int]]) -&gt; int:\n        direction=[(1,0),(-1,0),(0,1),(0,-1)]\n        row=len(grid)\n        col=len(grid[0])\n        time=0\n\n        rotten={(i,j) for i in range(row) for j in range(col) if grid[i][j]==2}\n        fresh={(i,j) for i in range(row) for j in range(col) if grid[i][j]==1}\n        #\u5f53\u5b58\u5728\u65b0\u9c9c\u6a58\u5b50\u65f6\uff0c\u7ee7\u7eed\u8fed\u4ee3\n        while fresh:\n        #\u5982\u679c\u8150\u70c2\u96c6\u5408\u4e3a\u7a7a\uff0c\u5219\u7ed3\u675f\u8fed\u4ee3\n            if not rotten:\n                return -1\n            rotten={(i+di,j+dj) for i,j in rotten for di,dj in direction if (i+di,j+dj) in fresh}\n            fresh-=rotten\n            time+=1\n        return time\n<\/code><\/pre>\n<h3>01\u80cc\u5305<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/lingbo.online\/wp-content\/uploads\/2023\/09\/bag.png\" alt=\"\" \/><\/p>\n<pre><code class=\"language-python\">f=[[0]*(m+1) for _ in range(n+1)]\ndef find_max():\n    #\u6709\u591a\u5c11\u7269\u54c1\u53ef\u9009\u62e9\n    for i in range(1,n+1):\n        #\u80cc\u5305\u7684\u5bb9\u91cf\u662f\u591a\u5c11\n        for j in range(1,m+1):\n            #\u5982\u679c\u80cc\u5305\u5bb9\u91cf\u5c0f\u4e8e\u7269\u54c1\u8d28\u91cf\n            if j&lt;v[i-1]:\n                #\u4e0d\u62ff\u8fd9\u4e2a\u7269\u54c1\n                f[i][j]=f[i-1][j]\n                else:\n                    #\u9009\u62e9\u6700\u597d\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u53bb\u4ef7\u503c\u7684\u8f83\u5927\u503c\n                    f[i][j]=max(f[i-1][j],f[i-1][j-v[i-1]]+w[i-1])<\/code><\/pre>\n<h3>\u5251\u6307Offer25. \u5408\u5e76\u4e24\u4e2a\u6392\u5e8f\u7684\u94fe\u8868<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/he-bing-liang-ge-pai-xu-de-lian-biao-lcof\/description\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/he-bing-liang-ge-pai-xu-de-lian-biao-lcof\/description\/<\/a><br \/>\n\u8f93\u5165\u4e24\u4e2a\u9012\u589e\u6392\u5e8f\u7684\u94fe\u8868\uff0c\u5408\u5e76\u8fd9\u4e24\u4e2a\u94fe\u8868\u5e76\u4f7f\u65b0\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u4ecd\u7136\u662f\u9012\u589e\u6392\u5e8f\u7684\u3002<\/p>\n<pre><code class=\"language-python\"># Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, x):\n#         self.val = x\n#         self.next = None\n\nclass Solution:\n    def mergeTwoLists(self, l1: ListNode, l2: ListNode) -&gt; ListNode:\n        dummy=ListNode(0)\n        tmp=dummy\n        while l1 and l2:\n            if l1.val&lt;=l2.val:\n                tmp.next=l1\n                l1=l1.next\n                tmp=tmp.next\n            else:\n                tmp.next=l2\n                l2=l2.next\n                tmp=tmp.next\n\n        while l1:\n            tmp.next=l1\n            l1=l1.next\n            tmp=tmp.next\n\n        while l2:\n            tmp.next=l2\n            l2=l2.next\n            tmp=tmp.next\n\n        return dummy.next<\/code><\/pre>\n<h3>\u9762\u8bd5\u989816.26 \u8ba1\u7b97\u5668<\/h3>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u6b63\u6574\u6570\u3001\u52a0(+)\u3001\u51cf(-)\u3001\u4e58(*)\u3001\u9664(\/)\u7684\u7b97\u6570\u8868\u8fbe\u5f0f(\u62ec\u53f7\u9664\u5916)\uff0c\u8ba1\u7b97\u5176\u7ed3\u679c\u3002<\/p>\n<p>\u8868\u8fbe\u5f0f\u4ec5\u5305\u542b\u975e\u8d1f\u6574\u6570\uff0c+\uff0c - \uff0c*\uff0c\/ \u56db\u79cd\u8fd0\u7b97\u7b26\u548c\u7a7a\u683c  \u3002 \u6574\u6570\u9664\u6cd5\u4ec5\u4fdd\u7559\u6574\u6570\u90e8\u5206\u3002<\/p>\n<p>\u5177\u4f53\u6765\u8bf4\uff0c\u904d\u5386\u5b57\u7b26\u4e32 s\uff0c\u5e76\u7528\u53d8\u91cf preSign \u8bb0\u5f55\u6bcf\u4e2a\u6570\u5b57\u4e4b\u524d\u7684\u8fd0\u7b97\u7b26\uff0c\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u6570\u5b57\uff0c\u5176\u4e4b\u524d\u7684\u8fd0\u7b97\u7b26\u89c6\u4e3a\u52a0\u53f7\u3002\u6bcf\u6b21\u904d\u5386\u5230\u6570\u5b57\u672b\u5c3e\u65f6\uff0c\u6839\u636e preSign \u6765\u51b3\u5b9a\u8ba1\u7b97\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>\u52a0\u53f7\uff1a\u5c06\u6570\u5b57\u538b\u5165\u6808\uff1b<\/li>\n<li>\u51cf\u53f7\uff1a\u5c06\u6570\u5b57\u7684\u76f8\u53cd\u6570\u538b\u5165\u6808\uff1b<\/li>\n<li>\u4e58\u9664\u53f7\uff1a\u8ba1\u7b97\u6570\u5b57\u4e0e\u6808\u9876\u5143\u7d20\uff0c\u5e76\u5c06\u6808\u9876\u5143\u7d20\u66ff\u6362\u4e3a\u8ba1\u7b97\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-python\">\nclass Solution:\n    def calculate(self, s: str) -&gt; int:\n        n=len(s)\n        num=0\n        stack=[]\n        presign=&#039;+&#039;\n\n        for i in range(n):\n            if s[i]!=&#039; &#039; and s[i].isdigit():\n                num=num*10+ord(s[i])-ord(&#039;0&#039;)\n            if i==n-1 or s[i] in &#039;+-*\/&#039;:\n                if presign==&#039;+&#039;:\n                    stack.append(num)\n                elif presign==&#039;-&#039;:\n                    stack.append(-num)\n                elif presign==&#039;*&#039;:\n                    stack.append(stack.pop()*num)\n                else:\n                    stack.append(int(stack.pop()\/num))\n                presign=s[i]\n                num=0\n        return sum(stack)<\/code><\/pre>\n<h3>Leecode55. \u8df3\u8dc3\u6e38\u620f<\/h3>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 nums \uff0c\u4f60\u6700\u521d\u4f4d\u4e8e\u6570\u7ec4\u7684 \u7b2c\u4e00\u4e2a\u4e0b\u6807 \u3002\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4f60\u5728\u8be5\u4f4d\u7f6e\u53ef\u4ee5\u8df3\u8dc3\u7684\u6700\u5927\u957f\u5ea6\u3002<br \/>\n\u5224\u65ad\u4f60\u662f\u5426\u80fd\u591f\u5230\u8fbe\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u8fd4\u56de true \uff1b\u5426\u5219\uff0c\u8fd4\u56de false \u3002<\/p>\n<pre><code class=\"language-pyhton\">class Solution:\n    def canJump(self, nums: List[int]) -&gt; bool:\n        #\u521d\u59cb\u5316\u5f53\u524d\u80fd\u8fbe\u5230\u6700\u8fdc\u7684\u4f4d\u7f6e\n        max_i=0\n        #i\u4e3a\u5f53\u524d\u4f4d\u7f6e\uff0cjump\u662f\u5f53\u524d\u4f4d\u7f6e\u7684\u8df3\u6570\n        for i,jump in enumerate(nums):\n            # \u5982\u679c\u5f53\u524d\u4f4d\u7f6e\u80fd\u8fbe\u5230\uff0c\u5e76\u4e14\u5f53\u524d\u4f4d\u7f6e+\u8df3\u6570&gt;\u6700\u8fdc\u4f4d\u7f6e\n            if max_i&gt;=i and i+jump&gt;max_i:\n                #\u66f4\u65b0\u6700\u8fdc\u80fd\u591f\u5230\u8fbe\u7684\u4f4d\u7f6e\n                max_i=i+jump\n        return max_i&gt;=i<\/code><\/pre>\n<h3>\u9762\u8bd5\u9898 08.01. \u4e09\u6b65\u95ee\u9898<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/three-steps-problem-lcci\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/three-steps-problem-lcci\/<\/a><br \/>\n\u4e09\u6b65\u95ee\u9898\u3002\u6709\u4e2a\u5c0f\u5b69\u6b63\u5728\u4e0a\u697c\u68af\uff0c\u697c\u68af\u6709n\u9636\u53f0\u9636\uff0c\u5c0f\u5b69\u4e00\u6b21\u53ef\u4ee5\u4e0a1\u9636\u30012\u9636\u62163\u9636\u3002\u5b9e\u73b0\u4e00\u79cd\u65b9\u6cd5\uff0c\u8ba1\u7b97\u5c0f\u5b69\u6709\u591a\u5c11\u79cd\u4e0a\u697c\u68af\u7684\u65b9\u5f0f\u3002\u7ed3\u679c\u53ef\u80fd\u5f88\u5927\uff0c\u4f60\u9700\u8981\u5bf9\u7ed3\u679c\u6a211000000007\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def waysToStep(self, n: int) -&gt; int:\n        dp=[1,1,2,4]\n\n        if n&lt;=3:\n            return dp[n]\n\n        for i in range(4,n+1):\n            dp.append((dp[-1]+dp[-2]+dp[-3])%1000000007)\n\n        return dp[n]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leecode56. \u5408\u5e76\u533a\u95f4 \u9898\u76ee\u94fe\u63a5\uff1ahttps:\/\/leetcode.cn\/problems\/merge-intervals &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/comments?post=448"}],"version-history":[{"count":14,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/448\/revisions"}],"predecessor-version":[{"id":506,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/448\/revisions\/506"}],"wp:attachment":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/media?parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/categories?post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/tags?post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}