Write a program to solve a Sudoku puzzle by filling the empty cells.
Empty cells is indicated by the character ‘.‘
.
Assume that there would be is only one unique solution.
A Sudoku Puzzle ...
Test instructions: Sudoku game
Thinking: Backtracking, is not a long time no write, open tag array is always wrong
Class Solution {Public:bool check (vector<vector<char> > &board, int position) {int x = Position/9;int y = position% 9;for (int i = 0; i < 9; i++) if (i! = x && board[i][y] = = Board[x][y]) return false; for (int j = 0; J < 9; J + +) if (j! = y && board[x][j] = = Board[x][y]) return false; for (int i = X/3 * 3, I < (X/3 + 1) * 3; i++) for (int j = Y/3 * 3; J < (Y/3 + 1) * 3; j + +) if (i! = x &am p;& J! = y && board[i][j] = = Board[x][y]) return false; return true; }bool Solve (vector<vector<char> > &board, int position) {if (position = = Bayi) return true;int row = position /9;int col = position% 9;if (board[row][col] = = '. ') {for (int i = 1; I <= 9; i++) {Board[row][col] = i + ' 0 '; if (check (board, position) && solve (board, position+1) ) return True;board[row][col] = '. ';}} else {if (Solve (board, position + 1)) return true;} return false;} void Solvesudoku (Vector<vector<char> > &boarD) {Solve (board, 0);}};
Leetcode Sudoku Solver