733. Flood Fill easy题
我好烂 我这完全没想到要怎么解
你们是写多少题才能直接自己写出来啊
class Solution {
public:
vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc,
int newcolor) {
if(image[sr][sc] == newcolor) return image;
int m = image.size();
int n = image[0].size();
floodFill(image, sc, sr, m, n, image[sr][sc], newcolor);
return image;
}
private:
void floodFill(vector<vector<int>>& image,
int x, int y, int m, int n, int origincolor, int
newcolor){
if(x<0 || x>=n || y<0 || y>=m) return;
if(image[y][x] != origincolor) return;
image[y][x] = newcolor;
floodFill(image, x+1, y, m, n, origincolor, newcolor);
floodFill(image, x-1, y, m, n, origincolor, newcolor);
floodFill(image, x, y+1, m, n, origincolor, newcolor);
floodFill(image, x, y-1, m, n, origincolor, newcolor);
}
};