LeetCode – Walls and Gates (Java)
Java Solution 1 – DFS public void wallsAndGates(int[][] rooms) { if(rooms==null || rooms.length==0||rooms[0].length==0) return; int m = rooms.length; int n = rooms[0].length; boolean[][] visited = new boolean[m][n]; for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ if(rooms[i][j]==0){ fill(rooms, i-1, j, 0, visited); fill(rooms, i, j+1, 0, visited); fill(rooms, i+1, j, 0, visited); fill(rooms, … Read more