classSolution{// Reappearance follow the leetcode official website solution of this questionpublicvoidsolve(char[][] board){if(board ==null|| board.length ==0)return;int n = board.length;int m = board[0].length;for(int i =0; i < n;++i){dfs(board, i,0);dfs(board, i, m -1);}// for(int i = 1; i < m - 1; ++j){ // carelessfor(int i =1; i < m -1;++i){dfs(board,0, i);dfs(board, n -1, i);}for(int i =0; i < n;++i){for(int j =0; j < m;++j){if(board[i][j]=='A'){
board[i][j]='O';}elseif(board[i][j]=='O'){
board[i][j]='X';}}}}// I can't judge it's 'O' or '0' in this quesion.// 深度优先遍历publicvoiddfs(char[][] board,int r,int c){int rl = board.length;int cl = board[0].length;// I can't judge it's 'O' or '0' in this quesion.if(r <0|| r >= rl || c <0|| c >= cl || board[r][c]!='O')return;
board[r][c]='A';// 作标记dfs(board, r -1, c);dfs(board, r +1, c);dfs(board, r, c +1);dfs(board, r, c -1);}// Reappearance follow the leetcode official website solution of this question}