{"id":2110,"date":"2022-01-16T17:49:50","date_gmt":"2022-01-16T09:49:50","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2110"},"modified":"2022-01-16T17:49:51","modified_gmt":"2022-01-16T09:49:51","slug":"leetcodeday-2","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/16\/leetcodeday-2\/","title":{"rendered":"leetcodeday &#8211;36 \u6709\u6548\u7684\u6570\u72ec"},"content":{"rendered":"\n<p>\u8bf7\u4f60\u5224\u65ad\u4e00\u4e2a&nbsp;<code>9 x 9<\/code>&nbsp;\u7684\u6570\u72ec\u662f\u5426\u6709\u6548\u3002\u53ea\u9700\u8981<strong>&nbsp;\u6839\u636e\u4ee5\u4e0b\u89c4\u5219<\/strong>&nbsp;\uff0c\u9a8c\u8bc1\u5df2\u7ecf\u586b\u5165\u7684\u6570\u5b57\u662f\u5426\u6709\u6548\u5373\u53ef\u3002<\/p>\n\n\n\n<ol><li>\u6570\u5b57&nbsp;<code>1-9<\/code>&nbsp;\u5728\u6bcf\u4e00\u884c\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002<\/li><li>\u6570\u5b57&nbsp;<code>1-9<\/code>&nbsp;\u5728\u6bcf\u4e00\u5217\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002<\/li><li>\u6570\u5b57&nbsp;<code>1-9<\/code>&nbsp;\u5728\u6bcf\u4e00\u4e2a\u4ee5\u7c97\u5b9e\u7ebf\u5206\u9694\u7684&nbsp;<code>3x3<\/code>&nbsp;\u5bab\u5185\u53ea\u80fd\u51fa\u73b0\u4e00\u6b21\u3002\uff08\u8bf7\u53c2\u8003\u793a\u4f8b\u56fe\uff09<\/li><\/ol>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n\n\n\n<ul><li>\u4e00\u4e2a\u6709\u6548\u7684\u6570\u72ec\uff08\u90e8\u5206\u5df2\u88ab\u586b\u5145\uff09\u4e0d\u4e00\u5b9a\u662f\u53ef\u89e3\u7684\u3002<\/li><li>\u53ea\u9700\u8981\u6839\u636e\u4ee5\u4e0a\u89c4\u5219\uff0c\u9a8c\u8bc1\u5df2\u7ecf\u586b\u5165\u7684\u6570\u5b57\u662f\u5426\u6709\u6548\u5373\u53ef\u3002<\/li><li>\u7a7a\u767d\u683c\u7528&nbsp;<code>'.'<\/code>&nbsp;\u8868\u793a\u3002<\/li><\/ul>\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-cn.com\/aliyun-lc-upload\/uploads\/2021\/04\/12\/250px-sudoku-by-l2g-20050714svg.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>board = \n[[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n<strong>\u8f93\u51fa\uff1a<\/strong>true\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>board = \n[[\"8\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n<strong>\u8f93\u51fa\uff1a<\/strong>false\n<strong>\u89e3\u91ca\uff1a<\/strong>\u9664\u4e86\u7b2c\u4e00\u884c\u7684\u7b2c\u4e00\u4e2a\u6570\u5b57\u4ece<strong> 5<\/strong> \u6539\u4e3a <strong>8 <\/strong>\u4ee5\u5916\uff0c\u7a7a\u683c\u5185\u5176\u4ed6\u6570\u5b57\u5747\u4e0e \u793a\u4f8b1 \u76f8\u540c\u3002 \u4f46\u7531\u4e8e\u4f4d\u4e8e\u5de6\u4e0a\u89d2\u7684 3x3 \u5bab\u5185\u6709\u4e24\u4e2a 8 \u5b58\u5728, \u56e0\u6b64\u8fd9\u4e2a\u6570\u72ec\u662f\u65e0\u6548\u7684\u3002<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u601d\u8def\uff1a\u904d\u5386\u4e00\u904d\u6570\u7ec4\uff0c\u5c31\u8981\u5b8c\u6210\u8be5\u76ee\u6807\uff0c\u884c\u548c\u5217\u7b80\u5355\uff0c\u5bf9\u4e8e\u65b9\u683c\uff1a&#91;int(i\/3)]&#91;int(j\/3)]\r\nclass Solution:\r\n    def isValidSudoku(self, board: List&#91;List&#91;str]]) -> bool:\r\n        # 1\u3001\u5148\u751f\u6210\u4e09\u4e2a\u6570\u7ec4\r\n        rows = &#91;&#91;0] * 9 for _ in range(9)]\r\n        columns = &#91;&#91;0] * 9 for _ in range(9)]\r\n        subboxes = &#91;&#91;&#91;0] * 9 for _ in range(3)] for _ in range(3)]\r\n        # \u904d\u5386\u884c\r\n        for i in range(9):\r\n            for j in range(9):\r\n                c = board&#91;i]&#91;j]\r\n                if c != '.':\r\n                    c = int(c) - 1\r\n                    rows&#91;i]&#91;c] += 1\r\n                    columns&#91;j]&#91;c] += 1\r\n                    subboxes&#91;int(i\/3)]&#91;int(j\/3)]&#91;c] += 1\r\n                    if rows&#91;i]&#91;c] > 1 or columns&#91;j]&#91;c]>1 or subboxes&#91;int(i\/3)]&#91;int(j\/3)]&#91;c]>1:\r\n                        return False\r\n        return True\r\n<\/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-235.png\" alt=\"\" class=\"wp-image-2112\" width=\"506\" height=\"117\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-235.png 753w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-235-300x70.png 300w\" sizes=\"(max-width: 506px) 100vw, 506px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u4f60\u5224\u65ad\u4e00\u4e2a&nbsp;9 x 9&nbsp;\u7684\u6570\u72ec\u662f\u5426\u6709\u6548\u3002\u53ea\u9700\u8981&nbsp;\u6839\u636e\u4ee5\u4e0b\u89c4\u5219&nbsp;\uff0c\u9a8c\u8bc1 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/16\/leetcodeday-2\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday &#8211;36 \u6709\u6548\u7684\u6570\u72ec<\/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\/2110"}],"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=2110"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2110\/revisions"}],"predecessor-version":[{"id":2113,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2110\/revisions\/2113"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2110"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}