MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / dfs

Method dfs

RegionsCutBySlashes.java:6–15  ·  view source on GitHub ↗
(int row, int col, int matrix[][])

Source from the content-addressed store, hash-verified

4 int dir[][] = {{-1,0},{0,1},{1,0},{0,-1}};
5 //visit all nodes of a component using DFS
6 public void dfs(int row, int col, int matrix[][]){
7 //out of bound, already visited, obstacle
8 if(row<0 || row>=rows || col<0 || col>=cols || matrix[row][col]==1){
9 return;
10 }
11 matrix[row][col] = 1;
12 for(int i=0;i<4;i++){
13 dfs(row + dir[i][0], col + dir[i][1], matrix);
14 }
15 }
16 public int regionsBySlashes(String[] grid) {
17 //create a 3*3 grid
18 int size = grid.length;

Callers 1

regionsBySlashesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected