{"id":1913,"date":"2016-03-28T19:45:55","date_gmt":"2016-03-28T11:45:55","guid":{"rendered":"http:\/\/boweihe.me\/?p=1913"},"modified":"2016-03-28T19:45:55","modified_gmt":"2016-03-28T11:45:55","slug":"leetcode-36-valid-sudoku","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=1913","title":{"rendered":"LeetCode 36. Valid Sudoku"},"content":{"rendered":"<p>Determine if a Sudoku is valid, according to: <a href=\"http:\/\/sudoku.com.au\/TheRules.aspx\">Sudoku Puzzles &#8211; The Rules<\/a>.<br \/>\nThe Sudoku board could be partially filled, where empty cells are filled with the character <code>'.'<\/code>.<br \/>\n<img decoding=\"async\" src=\"http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/f\/ff\/Sudoku-by-L2G-20050714.svg\/250px-Sudoku-by-L2G-20050714.svg.png\" alt=\"\" \/><br \/>\nA partially filled sudoku which is valid.<br \/>\n<b>Note:<\/b><br \/>\nA valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.<\/p>\n<h3>\u601d\u8def<\/h3>\n<p>\u884c\u641c\u7d22\u3001\u5217\u641c\u7d22\u3001sub-box\u641c\u7d22\uff0c\u6839\u636e\u89c4\u5219\u6765\u5c31\u884c\u4e86<\/p>\n<h3>\u4ee3\u7801<\/h3>\n<pre class=\"lang:c++ decode:true \">class Solution {\npublic:\n    bool isValidSudoku(vector&lt;vector&lt;char&gt;&gt;&amp; board) {\n        set&lt;char&gt; workingSet;\n        \/\/ Row\n        char c;\n        for(int row = 0; row&lt;9; row++){\n            workingSet.clear();\n            for(int col=0; col&lt;9; col++){\n                c = board[row][col];\n                if(c == '.')\n                    continue;\n                if(workingSet.count(c) &gt; 0)\n                    return false;\n                workingSet.insert(c);\n            }\n        }\n        \/\/ Col\n        for(int col = 0; col&lt;9; col++){\n            workingSet.clear();\n            for(int row=0; row&lt;9; row++){\n                c = board[row][col];\n                if(c == '.')\n                    continue;\n                if(workingSet.count(c) &gt; 0)\n                    return false;\n                workingSet.insert(c);\n            }\n        }\n        \/\/ Sub-box\n        for(int lPos=0; lPos &lt; 9; lPos+=3){\n            for(int tPos=0; tPos&lt;9; tPos+=3){\n                workingSet.clear();\n                for(int i=0; i&lt;3; i++){\n                    for(int j=0; j&lt;3; j++){\n                        c = board[lPos+i][tPos+j];\n                        if(c == '.')\n                            continue;\n                        if(workingSet.count(c) &gt; 0)\n                            return false;\n                        workingSet.insert(c);\n                    }\n                }\n            }\n        }\n        return true;\n    }\n};<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Determine if a Sudoku is valid, according to: Sudoku Puzzles &#8211; The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character &#8216;.&#8217;. A partially filled sudoku which is valid. Note: A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[66],"class_list":["post-1913","post","type-post","status-publish","format-standard","hentry","category-study","tag-leetcode-oj"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1913"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1913\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}