题目
链接
题解
class Solution {
public boolean isValidSudoku(char[][] board) {
// 定义哈希表
int[][] row = new int[9][9];
int[][] col = new int[9][9];
int[][][] miniBox = new int[3][3][9];
// 一次遍历
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
if (board[i][j] != '.') {
int c = board[i][j] - '0' - 1;
if (++row[i][c] > 1) {
return false;
}
if (++col[j][c] > 1) {
return false;
}
if (++miniBox[i / 3][j / 3][c] > 1) {
return false;
}
}
}
}
return true;
}
}