|
1 | | -# 36. Valid Sudoku |
| 1 | +36\. Valid Sudoku |
2 | 2 |
|
3 | | -## Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: |
| 3 | +Medium |
4 | 4 |
|
5 | | -1. Each row must contain the digits 1-9 without repetition. |
6 | | -2. Each column must contain the digits 1-9 without repetition. |
7 | | -3. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. |
| 5 | +Determine if a `9 x 9` Sudoku board is valid. Only the filled cells need to be validated **according to the following rules**: |
| 6 | + |
| 7 | +1. Each row must contain the digits `1-9` without repetition. |
| 8 | +2. Each column must contain the digits `1-9` without repetition. |
| 9 | +3. Each of the nine `3 x 3` sub-boxes of the grid must contain the digits `1-9` without repetition. |
8 | 10 |
|
9 | 11 | **Note:** |
10 | 12 |
|
|
15 | 17 |
|
16 | 18 |  |
17 | 19 |
|
18 | | -**Input:** |
| 20 | +**Input:** board = |
| 21 | + |
| 22 | +[["5","3",".",".","7",".",".",".","."] , |
| 23 | + |
| 24 | +["6",".",".","1","9","5",".",".","."] , |
| 25 | + |
| 26 | +[".","9","8",".",".",".",".","6","."] , |
| 27 | + |
| 28 | +["8",".",".",".","6",".",".",".","3"] , |
| 29 | + |
| 30 | +["4",".",".","8",".","3",".",".","1"] , |
| 31 | + |
| 32 | +["7",".",".",".","2",".",".",".","6"] , |
| 33 | + |
| 34 | +[".","6",".",".",".",".","2","8","."] , |
| 35 | + |
| 36 | +[".",".",".","4","1","9",".",".","5"] , |
19 | 37 |
|
20 | | - 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"]] |
| 38 | +[".",".",".",".","8",".",".","7","9"]] |
30 | 39 |
|
31 | | -**Output:** true |
| 40 | +**Output:** true |
32 | 41 |
|
33 | 42 | **Example 2:** |
34 | 43 |
|
35 | | -**Input:** |
| 44 | +**Input:** board = |
| 45 | + |
| 46 | +[["8","3",".",".","7",".",".",".","."] , |
| 47 | + |
| 48 | +["6",".",".","1","9","5",".",".","."] , |
| 49 | + |
| 50 | +[".","9","8",".",".",".",".","6","."] , |
| 51 | + |
| 52 | +["8",".",".",".","6",".",".",".","3"] , |
| 53 | + |
| 54 | +["4",".",".","8",".","3",".",".","1"] , |
| 55 | + |
| 56 | +["7",".",".",".","2",".",".",".","6"] , |
| 57 | + |
| 58 | +[".","6",".",".",".",".","2","8","."] , |
| 59 | + |
| 60 | +[".",".",".","4","1","9",".",".","5"] , |
36 | 61 |
|
37 | | - board = |
38 | | - [["8","3",".",".","7",".",".",".","."] |
39 | | - ,["6",".",".","1","9","5",".",".","."] |
40 | | - ,[".","9","8",".",".",".",".","6","."] |
41 | | - ,["8",".",".",".","6",".",".",".","3"] |
42 | | - ,["4",".",".","8",".","3",".",".","1"] |
43 | | - ,["7",".",".",".","2",".",".",".","6"] |
44 | | - ,[".","6",".",".",".",".","2","8","."] |
45 | | - ,[".",".",".","4","1","9",".",".","5"] |
46 | | - ,[".",".",".",".","8",".",".","7","9"]] |
| 62 | +[".",".",".",".","8",".",".","7","9"]] |
47 | 63 |
|
48 | 64 | **Output:** false |
49 | 65 |
|
50 | | -**Explanation:** Same as Example 1, except with the **5** in the top left corner being modified to **8**. Since there are two 8's in the top left 3x3 sub-box, it is invalid. |
| 66 | +**Explanation:** Same as Example 1, except with the **5** in the top left corner being modified to **8**. Since there are two 8's in the top left 3x3 sub-box, it is invalid. |
51 | 67 |
|
52 | 68 | **Constraints:** |
53 | 69 |
|
|
0 commit comments