-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_165floodFill.java
More file actions
27 lines (24 loc) · 829 Bytes
/
_165floodFill.java
File metadata and controls
27 lines (24 loc) · 829 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
import java.util.*;
public class _165floodFill {
public void helper(int[][] image, int sr,int sc,int color,boolean vis[][],int orgCol){
if(sr<0||sc<0||sr>=image.length||sc>=image[0].length ||
vis[sr][sc] || image[sr][sc]!= orgCol){
return;
}
//left
helper(image,sr,sc-1,color,vis,orgCol);
//right
helper(image,sr,sc+1,color,vis,orgCol);
//up
helper(image,sr-1,sc,color,vis,orgCol);
//down
helper(image,sr+1,sc,color,vis,orgCol);
}
public int[][] floodfill(int[][] image, int sr,int sc,int color){
boolean vis[][] = new boolean[image.length][image[0].length];
helper(image,sr,sc,color,vis,image[sr][sc]);
return image;
}
public static void main(String[] args) {
}
}