1 classSolution {2 Public:3 voidSolvesudoku (vector<vector<Char>>&Board) {4 Sudoku (board);5 }6 Private:7 BOOLSudoku (vector<vector<Char>>&Board)8 {9 for(inti =0; I <9; ++i) {Ten for(intj =0; J <9; ++j) { One if(Board[i][j] = ='.') { A for(intK =0; K <9; ++k) { -BOARD[I][J] ='1'+K; - if(IsValid (board, I, J) && Sudoku (board))return true; theBOARD[I][J] ='.'; - } - return false; - } + } - } + return true; A } at BOOLIsValid (vector<vector<Char>>& Board,intIintj) - { - for(intindex =0; Index <9; ++index) { - if(Index! = J && Board[i][index] = = Board[i][j])return false; - } - for(intindex =0; Index <9; ++index) { in if(Index! = i && board[index][j] = = Board[i][j])return false; - } to for(introw =3* (I/3); Row <3* (I/3) +3; ++row) { + for(intCol =3* (J/3); Col <3* (J/3) +3; ++Col) { - if(Row! = I | | Col! = j) && Board[row][col] = = Board[i][j])return false; the } * } $ return true;Panax Notoginseng } -};
037. Sudoku Solver