public static boolean isValidSudoku(char[][] board) { int length = board.length; for(int i=0; i<length; ++i){ HashSet<Character> lineSet = new HashSet<>(); HashSet<Character> colSet = new HashSet<>(); HashSet<Character> boxSet = new HashSet<>(); for (int j=0; j<length; ++j) { if(board[i][j] != '.' && !lineSet.add(board[i][j])){ return false; } if(board[j][i] != '.' && !colSet.add(board[j][i])){ return false; } int a = i / 3 * 3 + j / 3; int b = i % 3 * 3 + j % 3; if(board[a][b] != '.' && !boxSet.add(board[a][b])){ return false; } } } return true; }