1 题目
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.
Note:
A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
2 解法
public class Solution {
public boolean isValidSudoku(char[][] board) {
Set set = new HashSet();
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
char ch = board[i][j];
if(ch != '.'){
if(!set.add(ch + " int row: " + i) ||
!set.add(ch + " int colum: " + j)||
!set.add(ch + " int block: " + i/3 + "-" + j/3)){
return false;
}
}
}
}
return true;
}
}