733. Flood Fill Easy
1/**
2 * [733] Flood Fill
3 *
4 * An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.
5 * You are also given three integers sr, sc, and color. You should perform a flood fill on the image starting from the pixel image[sr][sc].
6 * To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of the aforementioned pixels with color.
7 * Return the modified image after performing the flood fill.
8 *
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2021/06/01/flood1-grid.jpg" style="width: 613px; height: 253px;" />
11 * Input: image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
12 * Output: [[2,2,2],[2,2,0],[2,0,1]]
13 * Explanation: From the center of the image with position (sr, sc) = (1, 1) (i.e., the red pixel), all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are colored with the new color.
14 * Note the bottom corner is not colored 2, because it is not 4-directionally connected to the starting pixel.
15 *
16 * Example 2:
17 *
18 * Input: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
19 * Output: [[0,0,0],[0,0,0]]
20 * Explanation: The starting pixel is already colored 0, so no changes are made to the image.
21 *
22 *
23 * Constraints:
24 *
25 * m == image.length
26 * n == image[i].length
27 * 1 <= m, n <= 50
28 * 0 <= image[i][j], color < 2^16
29 * 0 <= sr < m
30 * 0 <= sc < n
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/flood-fill/
36// discuss: https://leetcode.com/problems/flood-fill/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn flood_fill(image: Vec<Vec<i32>>, sr: i32, sc: i32, color: i32) -> Vec<Vec<i32>> {
42 vec![]
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_733() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.