-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay11.cpp
39 lines (33 loc) · 1.01 KB
/
Day11.cpp
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
28
29
30
31
32
33
34
35
36
37
38
39
/*
Author: Aryan Yadav
Flood Fill
Complexity:O()
Algorithm: NA
Difficulty: Medium
*/
class Solution
{
public:
void make(vector<vector<int>> &image, int currR, int currC, int currColor, int newColor)
{
int rows = image.size(), cols = image[0].size();
if (currR >= rows || currR < 0 || currC >= cols || currC < 0)
{
return;
}
else if (image[currR][currC] != currColor || image[currR][currC] == newColor)
{
return;
}
image[currR][currC] = newColor;
make(image, currR + 1, currC, currColor, newColor);
make(image, currR - 1, currC, currColor, newColor);
make(image, currR, currC + 1, currColor, newColor);
make(image, currR, currC - 1, currColor, newColor);
}
vector<vector<int>> floodFill(vector<vector<int>> &image, int sr, int sc, int newColor)
{
make(image, sr, sc, image[sr][sc], newColor);
return image;
}
};