-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray733.java
More file actions
30 lines (28 loc) · 907 Bytes
/
Array733.java
File metadata and controls
30 lines (28 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package array;
import java.util.ArrayList;
import java.util.List;
/**
* @ProjectName: leetcode
* @Package: array
* @ClassName: Array733
* @Author: markey
* @Description: 没看懂题意
* @Date: 2020/2/9 17:05
* @Version: 1.0
*/
public class Array733 {
public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
int color = image[sr][sc];
if (color != newColor) dfs(image, sr, sc, color, newColor);
return image;
}
public void dfs(int[][] image, int r, int c, int color, int newColor) {
if (image[r][c] == color) {
image[r][c] = newColor;
if (r >= 1) dfs(image, r-1, c, color, newColor);
if (c >= 1) dfs(image, r, c-1, color, newColor);
if (r+1 < image.length) dfs(image, r+1, c, color, newColor);
if (c+1 < image[0].length) dfs(image, r, c+1, color, newColor);
}
}
}