{"id":2840,"date":"2020-02-02T14:42:22","date_gmt":"2020-02-02T06:42:22","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2840"},"modified":"2020-02-02T14:42:22","modified_gmt":"2020-02-02T06:42:22","slug":"%e3%80%90leetcode%e3%80%910036-%e6%9c%89%e6%95%88%e7%9a%84%e6%95%b0%e7%8b%ac","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2840\/","title":{"rendered":"\u3010LeetCode\u30110036 \u6709\u6548\u7684\u6570\u72ec"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/valid-sudoku\/\">https:\/\/leetcode-cn.com\/problems\/valid-sudoku\/<\/a><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-<em>\n<\/em>class Solution(object):\n    def isValidSudoku(self, board):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> board: List[List[str]]\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: bool\n        \"\"\"\n        <\/em># \u68c0\u67e5\u6a2a\u6392\n        for i in range(9):\n            flag = ['1', '2', '3', '4', '5', '6', '7', '8', '9']\n            for j in range(9):\n                if board[i][j] is not '.':\n                    if board[i][j] in flag:\n                        flag.remove(board[i][j])\n                    else:\n                        return False\n        # \u68c0\u67e5\u7ad6\u6392\n        for i in range(9):\n            flag = ['1', '2', '3', '4', '5', '6', '7', '8', '9']\n            for j in range(9):\n                if board[j][i] is not '.':\n                    if board[j][i] in flag:\n                        flag.remove(board[j][i])\n                    else:\n                        return False\n        # \u68c0\u67e53*3\n        for i in range(0, 9, 3):\n            for j in range(0, 9, 3):\n                flag = ['1', '2', '3', '4', '5', '6', '7', '8', '9']\n                for x in range(i, i + 3):\n                    for y in range(j, j + 3):\n                        if board[x][y] is not '.':\n                            if board[x][y] in flag:\n                                flag.remove(board[x][y])\n                            else:\n                                return False\n        return True\nif __name__ == '__main__':\n    board = [[\"5\", \"3\", \".\", \".\", \"7\", \".\", \".\", \".\", \".\"], [\"6\", \".\", \".\", \"1\", \"9\", \"5\", \".\", \".\", \".\"],\n             [\".\", \"9\", \"8\", \".\", \".\", \".\", \".\", \"6\", \".\"], [\"8\", \".\", \".\", \".\", \"6\", \".\", \".\", \".\", \"3\"],\n             [\"4\", \".\", \".\", \"8\", \".\", \"3\", \".\", \".\", \"1\"], [\"7\", \".\", \".\", \".\", \"2\", \".\", \".\", \".\", \"6\"],\n             [\".\", \"6\", \".\", \".\", \".\", \".\", \"2\", \"8\", \".\"], [\".\", \".\", \".\", \"4\", \"1\", \"9\", \".\", \".\", \"5\"],\n             [\".\", \".\", \".\", \".\", \"8\", \".\", \".\", \"7\", \"9\"]]\n    print(Solution().isValidSudoku(board))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u67e5\uff0c\u5c31\u786c\u67e5\uff0c\u67e5\u4e09\u6b21\u3002<\/p>\n\n\n<p>\u4f9d\u6b21\u904d\u5386\u6a2a\u6392\u3001\u7ad6\u6392\u3002\u5982\u679c\u51fa\u73b0\u5c31\u5c06flag\u4e2d\u5bf9\u5e94\u6570\u5b57\u5220\u53bb\uff0c\u5982\u679c\u4e0d\u4e3a\u7a7a\u5e76\u4e14flag\u4e2d\u6ca1\u6709\u5219\u5224\u4e3a\u91cd\u590d\u51fa\u73b0\u8fd4\u56deFlase\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/valid-sudoku\/ # &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"views":1868,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2840"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2840"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2840\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2840"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}