We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 764f067 commit 5204165Copy full SHA for 5204165
flood-fill/main.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * @param {number[][]} image
3
+ * @param {number} sr
4
+ * @param {number} sc
5
+ * @param {number} color
6
+ * @return {number[][]}
7
+ */
8
+var floodFill = function(image, sr, sc, color) {
9
+ let current_color = image[sr][sc];
10
+ let height = image.length;
11
+ let width = image[0].length;
12
+
13
+ function dfs(sr, sc) {
14
+ if (sr >= 0 && sr < height && sc >= 0 && sc < width && image[sr][sc] == current_color && image[sr][sc] != color) {
15
+ image[sr][sc] = color;
16
+ dfs(sr+1, sc);
17
+ dfs(sr-1, sc);
18
+ dfs(sr, sc+1);
19
+ dfs(sr, sc-1);
20
+ }
21
22
23
+ dfs(sr, sc);
24
+ return image;
25
+};
26
0 commit comments