public char[][] updateBoard(char[][] board, int[] click) {
if (board == null || board.length == 0 || board[0].length == 0) {
int[][] directions = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
int row = click[0], col = click[1];
Queue<int[]> queue = new LinkedList<>();
while (!queue.isEmpty()) {
int[] curCell = queue.remove();
if (board[curRow][curCol] == 'M') {
board[curRow][curCol] = 'X';
for (int[] direction : directions) {
int nextRow = curRow + direction[0];
int nextCol = curCol + direction[1];
if (isValid(nextRow, nextCol, board)) {
if (board[nextRow][nextCol] == 'M') {
board[curRow][curCol] = (char)(mines + '0');
board[curRow][curCol] = 'B';
for (int[] direction : directions) {
int nextRow = curRow + direction[0];
int nextCol = curCol + direction[1];
if (isValid(nextRow, nextCol, board)) {
if (board[nextRow][nextCol] == 'E') {
board[nextRow][nextCol] = 'B';
queue.add(new int[] {nextRow, nextCol});
public boolean isValid(int row, int col, char[][] board) {
return row >= 0 && row < board.length && col >= 0 && col < board[0].length;