for (int col = 0; col < 9; col++){ Arrays.fill(visited,false);
for (int row = 0; row < 9; row++){ char current = board[col][row]; if (!process(visited,current)){ returnfalse; } } }
for (int row = 0; row < 9; row++){ Arrays.fill(visited,false);
for (int col = 0; col < 9; col++){ char current = board[col][row]; if (!process(visited,current)){ returnfalse; } } }
for (int i = 0; i < 9; i += 3){ for (int j = 0; j < 9; j += 3){ Arrays.fill(visited, false);
for (int k = 0; k < 9; k++){ // note use mod and division to track a small matrix char current = board[i + k % 3][j + k / 3]; if (!process(visited, current)){ returnfalse; } } } }
returntrue; }
publicbooleanprocess(boolean[] visited, char current){ if (current == '.') returntrue; int index = current - '1'; if (visited[index]) returnfalse; visited[index] = true; returntrue; } }