1034. Coloring A Border Medium

@problem@discussion
#Array#Depth-First Search#Breadth-First Search#Matrix



1/**
2 * [1034] Coloring A Border
3 *
4 * You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location.
5 * Two squares belong to the same connected component if they have the same color and are next to each other in any of the 4 directions.
6 * The border of a connected component is all the squares in the connected component that are either 4-directionally adjacent to a square not in the component, or on the boundary of the grid (the first or last row or column).
7 * You should color the border of the connected component that contains the square grid[row][col] with color.
8 * Return the final grid.
9 *  
10 * Example 1:
11 * Input: grid = [[1,1],[1,2]], row = 0, col = 0, color = 3
12 * Output: [[3,3],[3,2]]
13 * Example 2:
14 * Input: grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3
15 * Output: [[1,3,3],[2,3,3]]
16 * Example 3:
17 * Input: grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2
18 * Output: [[2,2,2],[2,1,2],[2,2,2]]
19 *  
20 * Constraints:
21 * 
22 * 	m == grid.length
23 * 	n == grid[i].length
24 * 	1 <= m, n <= 50
25 * 	1 <= grid[i][j], color <= 1000
26 * 	0 <= row < m
27 * 	0 <= col < n
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/coloring-a-border/
33// discuss: https://leetcode.com/problems/coloring-a-border/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn color_border(grid: Vec<Vec<i32>>, row: i32, col: i32, color: i32) -> Vec<Vec<i32>> {
39        vec![]
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_1034() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.