|
| 1 | +<h2><a href="https://leetcode.com/problems/valid-sudoku">36. Valid Sudokua>h2><h3>Mediumh3><hr><p>Determine if a <code>9 x 9code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rulesstrong>:p> |
| 2 | + |
| 3 | +<ol> |
| 4 | + Each row must contain the digits 1-9 without repetition. |
| 5 | + Each column must contain the digits 1-9 without repetition. |
| 6 | + Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. |
| 7 | +ol> |
| 8 | + |
| 9 | +<p><strong>Note:strong>p> |
| 10 | + |
| 11 | +<ul> |
| 12 | + A Sudoku board (partially filled) could be valid but is not necessarily solvable. |
| 13 | + Only the filled cells need to be validated according to the mentioned rules. |
| 14 | +ul> |
| 15 | + |
| 16 | +<p> p> |
| 17 | +<p><strong class="example">Example 1:strong>p> |
| 18 | +<img src="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><strong class="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>5strong> in the top left corner being modified to <strong>8strong>. Since there are two 839;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 | + board.length == 9 |
| 55 | + board[i].length == 9 |
| 56 | + board[i][j] is a digit 1-9 or '.' . |
| 57 | +ul> |
0 commit comments