|
|
|
|
/*/*******************************************************************************
|
|
|
|
|
** **
|
|
|
|
|
** Jiedi(China nanjing)Ltd. **
|
|
|
|
|
** 创建:丁宋涛 夏曹俊,此代码可用作为学习参考 **
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************FILE INFOMATION***********************************
|
|
|
|
|
**
|
|
|
|
|
** Project : 算法设计与编程实践---基于leetcode的企业真题库
|
|
|
|
|
** Contact : xiacaojun@qq.com
|
|
|
|
|
** 博客 : http://blog.csdn.net/jiedichina
|
|
|
|
|
** 视频课程 : 网易云课堂 http://study.163.com/u/xiacaojun
|
|
|
|
|
腾讯课堂 https://jiedi.ke.qq.com/
|
|
|
|
|
csdn学院 https://edu.csdn.net/course/detail/25037
|
|
|
|
|
** 51cto学院 http://edu.51cto.com/lecturer/index/user_id-100013755.html
|
|
|
|
|
** 老夏课堂 http://www.laoxiaketang.com
|
|
|
|
|
**
|
|
|
|
|
** 算法设计与编程实践---基于leetcode的企业真题库 课程群 :296249312 加入群下载代码和交流
|
|
|
|
|
** 微信公众号 : jiedi2007
|
|
|
|
|
** 头条号 : 夏曹俊
|
|
|
|
|
**
|
|
|
|
|
*****************************************************************************
|
|
|
|
|
//!!!!!!!!! 算法设计与编程实践---基于leetcode的企业真题库 课程 QQ群:296249312 下载代码和交流*/
|
|
|
|
|
/*
|
|
|
|
|
* @lc app=leetcode.cn id=733 lang=cpp
|
|
|
|
|
*
|
|
|
|
|
* [733] 图像渲染
|
|
|
|
|
*/
|
|
|
|
|
#include <vector>
|
|
|
|
|
using namespace std;
|
|
|
|
|
class Solution {
|
|
|
|
|
public:
|
|
|
|
|
void dfs(vector<vector<int>>& image,int i,int j,int oldColor,int newColor){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) {
|
|
|
|
|
if(image[sr][sc] == newColor)
|
|
|
|
|
return image;
|
|
|
|
|
|
|
|
|
|
int temp = image[sr][sc];
|
|
|
|
|
image[sr][sc] = newColor;
|
|
|
|
|
int row = image.size();
|
|
|
|
|
int col = image[0].size();
|
|
|
|
|
if(sr-1>=0 && image[sr-1][sc] == temp){
|
|
|
|
|
floodFill(image,sr-1,sc,newColor);
|
|
|
|
|
}
|
|
|
|
|
if(sr+1 <row && image[sr+1][sc] == temp)
|
|
|
|
|
floodFill(image,sr+1,sc,newColor);
|
|
|
|
|
|
|
|
|
|
if(sc-1>=0 && image[sr][sc-1] == temp)
|
|
|
|
|
floodFill(image,sr,sc-1,newColor);
|
|
|
|
|
|
|
|
|
|
if(sc+1<col && image[sr][sc+1] == temp)
|
|
|
|
|
floodFill(image,sr,sc+1,newColor);
|
|
|
|
|
|
|
|
|
|
return image;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|