hacktoberfest_2022
hacktoberfest_2022 copied to clipboard
Create FLOOD FILL IN A GRAPH.cpp
trafficstars
class Solution {
private:
void dfs(int row, int col, vector<vector
ans[row][col] = newColor;
int n = image.size();
int m = image[0].size();
for(int i = 0;i<4;i++) {
int nrow = row + delRow[i];
int ncol = col + delCol[i];
if(nrow>=0 && nrow<n && ncol>=0 && ncol < m &&
image[nrow][ncol] == iniColor && ans[nrow][ncol] != newColor) {
dfs(nrow, ncol, ans, image, newColor, delRow, delCol, iniColor);
}
}
}
public:
vector<vector
int iniColor = image[sr][sc];
vector<vector<int>> ans = image;
int delRow[] = {-1, 0, +1, 0};
int delCol[] = {0, +1, 0, -1};
dfs(sr, sc, ans, image, newColor, delRow, delCol, iniColor);
return ans;
}
};
please follow the id and mssg here i will merge it after 2 days bcs more than 150 pr are pending