题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cd6f1b1cae84b028ce7932c993fff0ea.png)
解题
public static void main(String[] args) {
char[][]board = {
{'5','3','.','.','7','.','.','.','.'},
{'6','.','.','1','9','5','.','.','.'},
{'.','9','8','.','.','.','.','6','.'},
{'8','.','.','.','6','.','.','.','3'},
{'4','.','.','8','.','3','.','.','1'},
{'7','.','.','.','2','.','.','.','6'},
{'.','6','.','.','.','.','2','8','.'},
{'.','.','.','4','1','9','.','.','5'},
{'.','.','.','.','8','.','.','7','9'}};
System.out.println(moveZeroes(board));
}
public static boolean moveZeroes(char[][]board) {
for (int i = 0; i < board.length; i++) {
Set setLine=new HashSet<>();
Set setCol=new HashSet<>();
Set setBox = new HashSet<>();
for (int j = 0; j < board[i].length; j++) {
if(board[i][j]!='.'&&!setLine.add(board[i][j])){
return false;
}
if(board[j][i]!='.'&&!setCol.add(board[j][i])){
return false;
}
if(i%3==0&&j%3==0){
for (int i1 = i; i1 < i+3; i1++) {
for (int j1 = j; j1 < j+3; j1++){
if(board[i1][j1]!='.'&&!setBox.add(board[i1][j1])){
return false;
}
}
}
}
setBox.clear();
}
}
return true;
}