|
| 1 | +<h2><ahref="https://leetcode.com/problems/valid-sudoku">36. Valid Sudoku</a></h2><h3>Medium</h3><hr><p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p> |
| 2 | + |
| 3 | +<ol> |
| 4 | +<li>Each row must contain the digits <code>1-9</code> without repetition.</li> |
| 5 | +<li>Each column must contain the digits <code>1-9</code> without repetition.</li> |
| 6 | +<li>Each of the nine <code>3 x 3</code> sub-boxes of the grid must contain the digits <code>1-9</code> without repetition.</li> |
| 7 | +</ol> |
| 8 | + |
| 9 | +<p><strong>Note:</strong></p> |
| 10 | + |
| 11 | +<ul> |
| 12 | +<li>A Sudoku board (partially filled) could be valid but is not necessarily solvable.</li> |
| 13 | +<li>Only the filled cells need to be validated according to the mentioned rules.</li> |
| 14 | +</ul> |
| 15 | + |
| 16 | +<p> </p> |
| 17 | +<p><strongclass="example">Example 1:</strong></p> |
| 18 | +<imgsrc="https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Sudoku-by-L2G-20050714.svg/250px-Sudoku-by-L2G-20050714.svg.png"style="height:250px;width:250px" /> |
| 19 | +<pre> |
| 20 | +<strong>Input:</strong> board = |
| 21 | +[["5","3",".",".","7",".",".",".","."] |
| 22 | +,["6",".",".","1","9","5",".",".","."] |
| 23 | +,[".","9","8",".",".",".",".","6","."] |
| 24 | +,["8",".",".",".","6",".",".",".","3"] |
| 25 | +,["4",".",".","8",".","3",".",".","1"] |
| 26 | +,["7",".",".",".","2",".",".",".","6"] |
| 27 | +,[".","6",".",".",".",".","2","8","."] |
| 28 | +,[".",".",".","4","1","9",".",".","5"] |
| 29 | +,[".",".",".",".","8",".",".","7","9"]] |
| 30 | +<strong>Output:</strong> true |
| 31 | +</pre> |
| 32 | + |
| 33 | +<p><strongclass="example">Example 2:</strong></p> |
| 34 | + |
| 35 | +<pre> |
| 36 | +<strong>Input:</strong> board = |
| 37 | +[["8","3",".",".","7",".",".",".","."] |
| 38 | +,["6",".",".","1","9","5",".",".","."] |
| 39 | +,[".","9","8",".",".",".",".","6","."] |
| 40 | +,["8",".",".",".","6",".",".",".","3"] |
| 41 | +,["4",".",".","8",".","3",".",".","1"] |
| 42 | +,["7",".",".",".","2",".",".",".","6"] |
| 43 | +,[".","6",".",".",".",".","2","8","."] |
| 44 | +,[".",".",".","4","1","9",".",".","5"] |
| 45 | +,[".",".",".",".","8",".",".","7","9"]] |
| 46 | +<strong>Output:</strong> false |
| 47 | +<strong>Explanation:</strong> Same as Example 1, except with the <strong>5</strong> in the top left corner being modified to <strong>8</strong>. Since there are two 8's in the top left 3x3 sub-box, it is invalid. |
| 48 | +</pre> |
| 49 | + |
| 50 | +<p> </p> |
| 51 | +<p><strong>Constraints:</strong></p> |
| 52 | + |
| 53 | +<ul> |
| 54 | +<li><code>board.length == 9</code></li> |
| 55 | +<li><code>board[i].length == 9</code></li> |
| 56 | +<li><code>board[i][j]</code> is a digit <code>1-9</code> or <code>'.'</code>.</li> |
| 57 | +</ul> |