class Solution { public: int n, m, w; vector<vector<int>> floodFill(vector<vector<int>> &image, int sr, int sc, int newColor) { n = image.size(); m = image[0].size(); w = image[sr][sc]; if (w != newColor) DFS(image, sr, sc, newColor); return image;
} void DFS(vector<vector<int>> &image, int x, int y, int c) { if (x < 0 || x >= n || y < 0 || y >= m || image[x][y] != w || image[x][y] == c) return; image[x][y] = c; DFS(image, x + 1, y, c); DFS(image, x - 1, y, c); DFS(image, x, y + 1, c); DFS(image, x, y - 1, c); } };
|