-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path735.asteroid-collision.java
35 lines (31 loc) · 1.01 KB
/
735.asteroid-collision.java
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
31
32
33
34
35
class Solution {
int[][] img;
int val;
int colr;
int[][] map;
public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
img = image;
val = image[sr][sc];
colr = newColor;
map = new int[image.length][image[0].length];
fill(sr, sc);
//if((0 <= sr && sr < image.length)){
// if(image[sr][sc])
// image = floodFill(image, sr+1 ,sc);
// image = floodFill(image, sr-1 ,sc);
// image = floodFill(image, sr ,sc+1);
// image = floodFill(image, sr ,sc-1);
return img;
}
public void fill(int sr, int sc){
if((0 <= sr && sr < img.length) && (0 <= sc && sc < img[0].length) && img[sr][sc] == val && map[sr][sc] != 1){
// System.out.println(sr+" "+sc);
map[sr][sc] = 1;
img[sr][sc] = colr;
fill(sr+1 ,sc);
fill(sr-1 ,sc);
fill(sr ,sc+1);
fill(sr ,sc-1);
}
}
}