欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

找出满足条件的圈

程序员文章站 2022-05-19 18:21:22
...

找出满足条件的圈


public class Solution {
    public void DFS(char[][]board,int row,int col){

      if(row<0||row>(board.length-1)||col<0||col>(board[0].length-1))
        return;
      if(board[row][col]=='O'){

          board[row][col]='*';
          DFS(board,row-1,col);
          DFS(board,row+1,col);
          DFS(board,row,col-1);
          DFS(board,row,col+1);
      }
    }

    public void solve(char[][]board){
      if(board.length<=0)  return;
      int row=board.length;
      int col=board[0].length;
      for(int i=0;i!=row;i++){
        DFS(board,i,col-1);
        DFS(board,i,0);
      }
      for(int i=0;i!=col;i++){
        DFS(board,0,i);
        DFS(board,row-1,i);
      }
      for(int i=0;i!=row;i++)
        for(int j=0;j!=col;j++)
        {

          if(board[i][j]=='O') board[i][j]='X';
          if(board[i][j]=='*') board[i][j]='O';

        }

    }

    public static void main(String[]args){
       // System.out.println("Hello");

    }
}