class Solution { int dx[8]={0, 0, -1,1,1, 1,-1,-1}; int dy[8]={1, -1, 0,0,1,-1,-1, 1}; public: void dfs(vector<vector<char>>& board, int i,int j){ if(board[i][j]!='E')return; int cnt=0; for(int k=0;k<8;k++){ if(i+dx[k]<0||i+dx[k]>=board.size()||j+dy[k]<0||j+dy[k]>=board[0].size())continue; if(board[i+dx[k]][j+dy[k]]=='M')cnt++; } if(cnt==0){//周围没有雷 board[i][j]='B'; for(int k=0;k<8;k++){ if(i+dx[k]<0||i+dx[k]>=board.size()||j+dy[k]<0||j+dy[k]>=board[0].size())continue; dfs(board,i+dx[k],j+dy[k]); } } else{ board[i][j]=cnt+'0';return; } return; } vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click) { int m=click[0],n=click[1]; if(board[m][n]=='M'){board[m][n]='X';return board;} dfs(board,m,n); return board; } };