DFS
733. 图像渲染
class Solution {
public:
vector<vector<int>> g;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
void dfs(int x, int y, int color, int newColor){
g[x][y] = newColor;
for(int i = 0; i < 4; i++){
int a = x + dx[i];
int b = y + dy[i];
if(a >= 0 && b >= 0 && a < g.size() && b < g[0].size() && g[a][b] == color){
dfs(a, b, color, newColor);
}
}
}
vector<vector<int>> floodFill(vector<vector<int>>& image, int x, int y, int newColor) {
g = image;
if(g[x][y] == newColor) return g;
dfs(x, y, g[x][y], newColor);
return g;
}
};695. 岛屿的最大面积
617. 合并二叉树
77. 组合
46. 全排列
784. 字母大小写全排列
216. 组合总和 III
17. 电话号码的字母组合
39. 组合总和
40. 组合总和 II
131. 分割回文串
93. 复原 IP 地址
78. 子集
90. 子集 II
491. 递增子序列
47. 全排列 II
79. 单词搜索
200. 岛屿数量
22. 括号生成
4. 寻找两个正序数组的中位数
最后更新于