// https://leetcode.com/problems/surrounded-regions/ import java.util.*; import java.io.*; class Main { static class Node{ int row; int col; Node(int row, int col){ this.row = row; this.col = col; } } // DFS public static void dfs(Node node, char board[][], boolean doNotTouch[][]){ int m = board.length; int n = board[0].length; int r = node.row; int c = node.col; doNotTouch[r][c] = true; int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; for(int k=0;k<4;k++){ int nr = r + dr[k]; int nc = c + dc[k]; if(nr>=0 && nc>=0 && nr q = new LinkedList<>(); q.add(start); doNotTouch[start.row][start.col] = true; int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; while(!q.isEmpty()){ Node cur = q.poll(); for(int k=0;k<4;k++){ int nr = cur.row + dr[k]; int nc = cur.col + dc[k]; if(nr>=0 && nc>=0 && nr