# 被围绕的区域

给你一个 <code>m x n</code> 的矩阵 <code>board</code> ，由若干字符 <code>'X'</code> 和 <code>'O'</code> ，找到所有被 <code>'X'</code> 围绕的区域，并将这些区域里所有的 <code>'O'</code> 用 <code>'X'</code> 填充。
<div class="original__bRMd">
<div>
<p> </p>

<p><strong>示例 1：</strong></p>
<img alt="" src="https://img-service.csdnimg.cn/img_convert/5a3a22bfad68fd1d22012a0ee48ec665.jpeg" style="width: 550px; height: 237px;" />
<pre>
<strong>输入：</strong>board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
<strong>输出：</strong>[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]
<strong>解释：</strong>被围绕的区间不会存在于边界上，换句话说，任何边界上的 <code>'O'</code> 都不会被填充为 <code>'X'</code>。 任何不在边界上，或不与边界上的 <code>'O'</code> 相连的 <code>'O'</code> 最终都会被填充为 <code>'X'</code>。如果两个元素在水平或垂直方向相邻，则称它们是“相连”的。
</pre>

<p><strong>示例 2：</strong></p>

<pre>
<strong>输入：</strong>board = [["X"]]
<strong>输出：</strong>[["X"]]
</pre>

<p> </p>

<p><strong>提示：</strong></p>

<ul>
	<li><code>m == board.length</code></li>
	<li><code>n == board[i].length</code></li>
	<li><code>1 <= m, n <= 200</code></li>
	<li><code>board[i][j]</code> 为 <code>'X'</code> 或 <code>'O'</code></li>
</ul>
</div>
</div>


## template

```java

class Solution {
	int[] dx = { 1, -1, 0, 0 };
	int[] dy = { 0, 0, 1, -1 };

	public void solve(char[][] board) {
		int n = board.length;
		if (n == 0) {
			return;
		}
		int m = board[0].length;
		Queue<int[]> queue = new LinkedList<int[]>();
		for (int i = 0; i < n; i++) {
			if (board[i][0] == 'O') {
				queue.offer(new int[] { i, 0 });
			}
			if (board[i][m - 1] == 'O') {
				queue.offer(new int[] { i, m - 1 });
			}
		}
		for (int i = 1; i < m - 1; i++) {
			if (board[0][i] == 'O') {
				queue.offer(new int[] { 0, i });
			}
			if (board[n - 1][i] == 'O') {
				queue.offer(new int[] { n - 1, i });
			}
		}
		while (!queue.isEmpty()) {
			int[] cell = queue.poll();
			int x = cell[0], y = cell[1];
			board[x][y] = 'A';
			for (int i = 0; i < 4; i++) {
				int mx = x + dx[i], my = y + dy[i];
				if (mx < 0 || my < 0 || mx >= n || my >= m || board[mx][my] != 'O') {
					continue;
				}
				queue.offer(new int[] { mx, my });
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (board[i][j] == 'A') {
					board[i][j] = 'O';
				} else if (board[i][j] == 'O') {
					board[i][j] = 'X';
				}
			}
		}
	}
}

```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```