1 topics
Determine if a Sudoku is valid, according To:sudoku puzzles-the Rules.
The Sudoku board could be partially filled, where empty cells is filled with the character ‘.‘
.
A partially filled sudoku which is valid.
Note:
A Valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
2 Ideas
At first I thought it was completely filled out, see if I can fill it out at the end.
The title of the result is based on the data that is already in place to determine whether it has been hung. This is also read other people's code to know.
3 Code:
//Only need to examin the providing num is Valid intLen =board.length; boolean[][] Row=NewBoolean[len][len]; boolean[][] Column=NewBoolean[len][len]; Boolean[][] Sub=NewBoolean[len][len]; for(inti =0; i < sub.length; i++) {Arrays.fill (row[i],false); Arrays.fill (Column[i],false); Arrays.fill (Sub[i],false); } for(intI=0; i<len;i++){ for(intj=0; j<len;j++){ if(Board[i][j]! ='.'){ intnum = board[i][j]-'1'; intK = i/3*3+j/3; if(Row[i][num] | | column[j][num] | |Sub[k][num]) { return false; } Row[i][num]=column[j][num]=sub[k][num] =true; } } } return true; }
[Leetcode] Valid Sudoku