|
3 | 3 | import java.util.LinkedList;
|
4 | 4 | import java.util.Queue;
|
5 | 5 |
|
6 |
| -/** |
7 |
| - * 733. Flood Fill |
8 |
| - * |
9 |
| - * An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535). |
10 |
| - * Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. |
11 |
| - * To perform a "flood fill", consider the starting pixel, plus any pixels connected 4-directionally to the starting |
12 |
| - * pixel of the same color as the starting pixel, |
13 |
| - * plus any pixels connected 4-directionally to those pixels (also with the same color as the starting pixel), and so on. |
14 |
| - * Replace the color of all of the aforementioned pixels with the newColor. |
15 |
| - * At the end, return the modified image. |
16 |
| -
|
17 |
| - Example 1: |
18 |
| - Input: |
19 |
| - image = [[1,1,1],[1,1,0],[1,0,1]] |
20 |
| - sr = 1, sc = 1, newColor = 2 |
21 |
| - Output: [[2,2,2],[2,2,0],[2,0,1]] |
22 |
| -
|
23 |
| - Explanation: |
24 |
| - From the center of the image (with position (sr, sc) = (1, 1)), all pixels connected |
25 |
| - by a path of the same color as the starting pixel are colored with the new color. |
26 |
| - Note the bottom corner is not colored 2, because it is not 4-directionally connected |
27 |
| - to the starting pixel. |
28 |
| -
|
29 |
| - Note: |
30 |
| - The length of image and image[0] will be in the range [1, 50]. |
31 |
| - The given starting pixel will satisfy 0 <= sr < image.length and 0 <= sc < image[0].length. |
32 |
| - The value of each color in image[i][j] and newColor will be an integer in [0, 65535]. |
33 |
| - */ |
34 | 6 | public class _733 {
|
35 | 7 | public static class Solution1 {
|
36 | 8 | public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
|
|
0 commit comments