diff --git a/src/main/java/leetcode/editor/cn/ColoringABorder.java b/src/main/java/leetcode/editor/cn/ColoringABorder.java
new file mode 100644
index 0000000..060d4e3
--- /dev/null
+++ b/src/main/java/leetcode/editor/cn/ColoringABorder.java
@@ -0,0 +1,112 @@
+//
给你一个大小为 m x n
的整数矩阵 grid
,表示一个网格。另给你三个整数 row
、col
和 color
。网格中的每个值表示该位置处的网格块的颜色。
+//
+//两个网格块属于同一 连通分量 需满足下述全部条件:
+//
+//
+// - 两个网格块颜色相同
+// - 在上、下、左、右任意一个方向上相邻
+//
+//
+//连通分量的边界 是指连通分量中满足下述条件之一的所有网格块:
+//
+//
+// - 在上、下、左、右任意一个方向上与不属于同一连通分量的网格块相邻
+// - 在网格的边界上(第一行/列或最后一行/列)
+//
+//
+//请你使用指定颜色 color
为所有包含网格块 grid[row][col]
的 连通分量的边界 进行着色,并返回最终的网格 grid
。
+//
+//
+//
+//示例 1:
+//
+//
+//输入:grid = [[1,1],[1,2]], row = 0, col = 0, color = 3
+//输出:[[3,3],[3,2]]
+//
+//示例 2:
+//
+//
+//输入:grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3
+//输出:[[1,3,3],[2,3,3]]
+//
+//示例 3:
+//
+//
+//输入:grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2
+//输出:[[2,2,2],[2,1,2],[2,2,2]]
+//
+//
+//
+//提示:
+//
+//
+// m == grid.length
+// n == grid[i].length
+// 1 <= m, n <= 50
+// 1 <= grid[i][j], color <= 1000
+// 0 <= row < m
+// 0 <= col < n
+//
+//
+//
+//
+//Related Topics
深度优先搜索广度优先搜索数组矩阵
👍 159👎 0
+package leetcode.editor.cn;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+// 1034:边界着色
+public class ColoringABorder {
+ public static void main(String[] args) {
+ Solution solution = new ColoringABorder().new Solution();
+ // TO TEST
+ }
+
+ //leetcode submit region begin(Prohibit modification and deletion)
+ class Solution {
+ public int[][] colorBorder(int[][] grid, int row, int col, int color) {
+ int xLength = grid.length;
+ int yLength = grid[0].length;
+ boolean[][] use = new boolean[xLength][yLength];
+ int[][] res = new int[xLength][yLength];
+ Queue queue = new LinkedList<>();
+ queue.add(new int[]{row, col});
+ use[row][col] = true;
+ int[] xArr = new int[]{-1, 1, 0, 0};
+ int[] yArr = new int[]{0, 0, -1, 1};
+ int ori = grid[row][col];
+ while (!queue.isEmpty()) {
+ int[] point = queue.poll();
+ int num = 0;
+ for (int i = 0; i < 4; i++) {
+ int x = point[0] + xArr[i];
+ int y = point[1] + yArr[i];
+ if (x >= xLength || x < 0 || y >= yLength || y < 0
+ || grid[x][y] != ori) {
+ continue;
+ }
+ num++;
+ if (!use[x][y]) {
+ use[x][y] = true;
+ queue.add(new int[]{x, y});
+ }
+ }
+ if (num < 4) {
+ res[point[0]][point[1]] = color;
+ }
+ }
+ for (int i = 0; i < xLength; i++) {
+ for (int j = 0; j < yLength; j++) {
+ if (res[i][j] == 0) {
+ res[i][j] = grid[i][j];
+ }
+ }
+ }
+ return res;
+ }
+ }
+//leetcode submit region end(Prohibit modification and deletion)
+
+}
diff --git a/src/main/java/leetcode/editor/cn/doc/content/ColoringABorder.md b/src/main/java/leetcode/editor/cn/doc/content/ColoringABorder.md
new file mode 100644
index 0000000..8251a78
--- /dev/null
+++ b/src/main/java/leetcode/editor/cn/doc/content/ColoringABorder.md
@@ -0,0 +1,54 @@
+给你一个大小为 m x n
的整数矩阵 grid
,表示一个网格。另给你三个整数 row
、col
和 color
。网格中的每个值表示该位置处的网格块的颜色。
+
+两个网格块属于同一 连通分量 需满足下述全部条件:
+
+
+ - 两个网格块颜色相同
+ - 在上、下、左、右任意一个方向上相邻
+
+
+连通分量的边界 是指连通分量中满足下述条件之一的所有网格块:
+
+
+ - 在上、下、左、右任意一个方向上与不属于同一连通分量的网格块相邻
+ - 在网格的边界上(第一行/列或最后一行/列)
+
+
+请你使用指定颜色 color
为所有包含网格块 grid[row][col]
的 连通分量的边界 进行着色,并返回最终的网格 grid
。
+
+
+
+示例 1:
+
+
+输入:grid = [[1,1],[1,2]], row = 0, col = 0, color = 3
+输出:[[3,3],[3,2]]
+
+示例 2:
+
+
+输入:grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3
+输出:[[1,3,3],[2,3,3]]
+
+示例 3:
+
+
+输入:grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2
+输出:[[2,2,2],[2,1,2],[2,2,2]]
+
+
+
+提示:
+
+
+ m == grid.length
+ n == grid[i].length
+ 1 <= m, n <= 50
+ 1 <= grid[i][j], color <= 1000
+ 0 <= row < m
+ 0 <= col < n
+
+
+
+
+Related Topics
深度优先搜索广度优先搜索数组矩阵
👍 159👎 0
\ No newline at end of file