private boolean isValid(char[][] board, int row, int col, int n) {
        for (int c = 0; c < 9; ++c) {
            if (board[row][c] == n) return false;
        }
        for (int r = 0; r < 9; ++r) {
            if (board[r][col] == n) return false;
        }
        for (int r = row/3*3; r < row/3*3 + 3; ++r) {
            for (int c = col/3*3; c < col/3*3 + 3; ++c) {
                if (board[r][c] == n) return false;
            }
        }
        return true;
    }