Complete DFS-1#1407
Conversation
Flood Fill the image (FloodFill.java)Your solution is correct and well-implemented. Both BFS and DFS are valid approaches for flood fill. Here are some points for improvement:
Example improvement for DFS (without passing constant parameters): class Solution {
private static final int[][] DIRS = {{0,1}, {1,0}, {-1,0}, {0,-1}};
public int[][] floodFill(int[][] image, int sr, int sc, int color) {
int oldColor = image[sr][sc];
if (oldColor == color) return image;
int n = image.length, m = image[0].length;
dfs(image, sr, sc, n, m, oldColor, color);
return image;
}
private void dfs(int[][] image, int i, int j, int n, int m, int oldColor, int color) {
if (i < 0 || j < 0 || i >= n || j >= m || image[i][j] != oldColor) return;
image[i][j] = color;
for (int[] dir : DIRS) {
dfs(image, i + dir[0], j + dir[1], n, m, oldColor, color);
}
}
}Note: In this version, Overall, your solution is correct and efficient. Good job! VERDICT: PASS Nearest zero (01Matrix.java)Your solution is well-implemented and follows the standard BFS approach for this problem. Here are some strengths and suggestions: Strengths:
Areas for Improvement:
Minor Note:
Overall, excellent job! VERDICT: PASS |
No description provided.