{"id":2309,"date":"2022-01-23T19:43:08","date_gmt":"2022-01-23T11:43:08","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2309"},"modified":"2022-01-23T19:43:09","modified_gmt":"2022-01-23T11:43:09","slug":"leetcodeday63","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/23\/leetcodeday63\/","title":{"rendered":"leetcodeday63 &#8211;\u4e0d\u540c\u8def\u5f84 II"},"content":{"rendered":"\n<p>\u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a&nbsp;<em>m x n&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>\u73b0\u5728\u8003\u8651\u7f51\u683c\u4e2d\u6709\u969c\u788d\u7269\u3002\u90a3\u4e48\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u5c06\u4f1a\u6709\u591a\u5c11\u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1f<\/p>\n\n\n\n<p>\u7f51\u683c\u4e2d\u7684\u969c\u788d\u7269\u548c\u7a7a\u4f4d\u7f6e\u5206\u522b\u7528&nbsp;<code>1<\/code>&nbsp;\u548c&nbsp;<code>0<\/code>&nbsp;\u6765\u8868\u793a\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/assets.leetcode.com\/uploads\/2020\/11\/04\/robot1.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>obstacleGrid = &#91;&#91;0,0,0],&#91;0,1,0],&#91;0,0,0]]\n<strong>\u8f93\u51fa\uff1a<\/strong>2\n<strong>\u89e3\u91ca\uff1a<\/strong>\n3x3 \u7f51\u683c\u7684\u6b63\u4e2d\u95f4\u6709\u4e00\u4e2a\u969c\u788d\u7269\u3002\n\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u4e00\u5171\u6709 2 \u6761\u4e0d\u540c\u7684\u8def\u5f84\uff1a\n1. \u5411\u53f3 -&gt; \u5411\u53f3 -&gt; \u5411\u4e0b -&gt; \u5411\u4e0b\n2. \u5411\u4e0b -&gt; \u5411\u4e0b -&gt; \u5411\u53f3 -&gt; \u5411\u53f3<\/code><\/pre>\n\n\n\n<p>\u52a8\u6001\u89c4\u5212\uff1adp[i][j]\u8868\u793a\u4ece00\u5230ij\u7684\u6240\u6709\u53ef\u80fd\u7684\u8def\u5f84\u6570\u91cf\uff08\u4e00\u822cdp\u6570\u7ec4\u5c31\u8868\u793a\u6211\u4eec\u8981\u6c42\u7684\u7ed3\u679c\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"545\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-275-1024x545.png\" alt=\"\" class=\"wp-image-2311\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-275-1024x545.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-275-300x160.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-275-768x408.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-275.png 1303w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\r\n    def uniquePathsWithObstacles(self, obstacleGrid: List&#91;List&#91;int]]) -> int:\r\n\r\n        m, n = len(obstacleGrid), len(obstacleGrid&#91;0])\r\n        if m == 1 and n == 1:\r\n            if obstacleGrid&#91;0]&#91;0] == 1: return 0\r\n            else: return 1\r\n        \r\n        dp = &#91;&#91;0] * n for _ in range(m)]\r\n\r\n        for i in range(m):\r\n            if obstacleGrid&#91;i]&#91;0] == 1: break\r\n            dp&#91;i]&#91;0] = 1\r\n        \r\n        for j in range(n):\r\n            if obstacleGrid&#91;0]&#91;j] == 1: break\r\n            dp&#91;0]&#91;j] = 1\r\n        \r\n        for i in range(1, m):\r\n            for j in range(1, n):\r\n                if obstacleGrid&#91;i]&#91;j] == 1:\r\n                    dp&#91;i]&#91;j] = 0\r\n                else:\r\n                    dp&#91;i]&#91;j] = dp&#91;i-1]&#91;j] + dp&#91;i]&#91;j-1]\r\n        \r\n        return dp&#91;-1]&#91;-1]<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-276.png\" alt=\"\" class=\"wp-image-2313\" width=\"537\" height=\"148\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-276.png 831w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-276-300x83.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-276-768x213.png 768w\" sizes=\"(max-width: 537px) 100vw, 537px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u673a\u5668\u4eba\u4f4d\u4e8e\u4e00\u4e2a&nbsp;m x n&nbsp;\u7f51\u683c\u7684\u5de6\u4e0a\u89d2 \uff08\u8d77\u59cb\u70b9\u5728\u4e0b\u56fe\u4e2d\u6807\u8bb0\u4e3a\u201cStart\u201d \uff09\u3002  &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/23\/leetcodeday63\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday63 &#8211;\u4e0d\u540c\u8def\u5f84 II<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2309"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2309"}],"version-history":[{"count":4,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2309\/revisions"}],"predecessor-version":[{"id":2315,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2309\/revisions\/2315"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2309"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}