|
3 | 3 | /**
|
4 | 4 | * 37. Sudoku Solver
|
5 | 5 | *
|
6 |
| - * Write a program to solve a Sudoku puzzle by filling the empty cells. |
7 |
| - * Empty cells are indicated by the character '.'. |
8 |
| - * You may assume that there will be only one unique solution. |
| 6 | + * Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: |
| 7 | + * |
| 8 | + * Each row must contain the digits 1-9 without repetition. |
| 9 | + * Each column must contain the digits 1-9 without repetition. |
| 10 | + * Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition. |
| 11 | + * |
| 12 | + * The Sudoku board could be partially filled, where empty cells are filled with the character '.'. |
| 13 | + * |
| 14 | + * Example 1: |
| 15 | + * |
| 16 | + * Input: |
| 17 | + * [ |
| 18 | + * ["5","3",".",".","7",".",".",".","."], |
| 19 | + * ["6",".",".","1","9","5",".",".","."], |
| 20 | + * [".","9","8",".",".",".",".","6","."], |
| 21 | + * ["8",".",".",".","6",".",".",".","3"], |
| 22 | + * ["4",".",".","8",".","3",".",".","1"], |
| 23 | + * ["7",".",".",".","2",".",".",".","6"], |
| 24 | + * [".","6",".",".",".",".","2","8","."], |
| 25 | + * [".",".",".","4","1","9",".",".","5"], |
| 26 | + * [".",".",".",".","8",".",".","7","9"] |
| 27 | + * ] |
| 28 | + * Output: true |
| 29 | + * Example 2: |
| 30 | + * |
| 31 | + * Input: |
| 32 | + * [ |
| 33 | + * ["8","3",".",".","7",".",".",".","."], |
| 34 | + * ["6",".",".","1","9","5",".",".","."], |
| 35 | + * [".","9","8",".",".",".",".","6","."], |
| 36 | + * ["8",".",".",".","6",".",".",".","3"], |
| 37 | + * ["4",".",".","8",".","3",".",".","1"], |
| 38 | + * ["7",".",".",".","2",".",".",".","6"], |
| 39 | + * [".","6",".",".",".",".","2","8","."], |
| 40 | + * [".",".",".","4","1","9",".",".","5"], |
| 41 | + * [".",".",".",".","8",".",".","7","9"] |
| 42 | + * ] |
| 43 | + * Output: false |
| 44 | + * Explanation: Same as Example 1, except with the 5 in the top left corner being |
| 45 | + * modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid. |
| 46 | + * Note: |
| 47 | + * |
| 48 | + * A Sudoku board (partially filled) could be valid but is not necessarily solvable. |
| 49 | + * Only the filled cells need to be validated according to the mentioned rules. |
| 50 | + * The given board contain only digits 1-9 and the character '.'. |
| 51 | + * The given board size is always 9x9. |
| 52 | + * |
9 | 53 | */
|
10 | 54 | publicclass_37 {
|
11 | 55 |
|
|