Description
Determine whether a Sudoku is valid.
The Sudoku board could be partially filled, where empty cells is filled with the character .
.
A Valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
Clarification
What's Sudoku
?
- Http://sudoku.com.au/TheRules.aspx
- https://zh.wikipedia.org/wiki/Sudoku
- Https://en.wikipedia.org/wiki/Sudoku
- Http://baike.baidu.com/subview/961/10842669.htm
Example
The following partially filed Sudoku is valid.
Problem solving: Judging whether Sudoku is effective. If the number in each row, column, or small square is not duplicated, it is valid. Of course, the premise must be between 1~9. The blank part of the question is used. "To be careful," he said. To do this, check the rows, columns, and squares, take these numbers out, put them in a one-dimensional array, and judge the number of the one-dimensional array, full of the corresponding conditions. The code is as follows:
Public classSolution {/** * @paramboard:the Board *@return: Whether the Sudoku is valid*/ Public BooleanIsvalidsudoku (Char[] board) { //Write your code here Char[]temp =New Char[9]; for(inti = 0; I < 9; i++){ //Check Row for(intj = 0; J < 9; J + +) {Temp[j]=Board[i][j]; } if(Judge (temp) = =false){ return false; } //Check Column for(intj = 0; J < 9; J + +) {Temp[j]=Board[j][i]; } if(Judge (temp) = =false){ return false; } } //Small Lattice for(inti = 0; I < 3; i++){ for(intj = 0; J < 3; J + +){ intb = 0; for(intK = 0 + i * 3; K < 3 + i * 3; k++){ for(intm = 0 + J * 3; M < 3 + J * 3; m++) {temp[b++] =Board[k][m]; } } if(Judge (temp) = =false) return false; } } return true; } Public BooleanJudgeChar[]temp] { for(inti = 0; I < 9; i++){ if(Temp[i] > ' 9 ' | | temp[i] < ' 1 ' ){ if(Temp[i]! = '. ') return false; } } for(inti = 1; I < 9; i++){ for(intj = 0; J < I; J + +){ if(Temp[i] = =Temp[j]) { if(Temp[i]! = '. ') return false; } } } return true; }}
389. Valid Sudoku "Lintcode java"