-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode 733.cpp
More file actions
25 lines (22 loc) · 785 Bytes
/
Leetcode 733.cpp
File metadata and controls
25 lines (22 loc) · 785 Bytes
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
class Solution {
private:
void dfs(int row, int col , vector<vector<int>>& image, int &initial, int &color, int &n, int &m){
if(row<0 || row>=n || col< 0 || col>=m || image[row][col]!=initial){
return;
}
image[row][col]=color;
// neighbours
dfs(row-1,col,image,initial,color,n,m);
dfs(row,col-1,image,initial,color,n,m);
dfs(row+1,col,image,initial,color,n,m);
dfs(row,col+1,image,initial,color,n,m);
}
public:
vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
int n = image.size();
int m = image[0].size();
int initial = image[sr][sc];
dfs(sr,sc,image,initial, color,n,m);
return image;
}
};