problem

733. Flood Fill

题意:图像处理中的泛洪填充算法,常见的有四邻域像素填充法、八邻域像素填充法、基于扫描线的像素填充法,实现方法分为递归与非递归(基于栈)。

泛洪填充算法原理:从某个像素点开始,将封闭区域内的所有此像素值位置的元素填充为新颜色。

solution1: 递归方法;

class Solution {
public:
vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) {
if(image[sr][sc] == newColor) return image;
helper(image, sr, sc, image[sr][sc], newColor);
return image;
}
void helper(vector<vector<int>>& image, int i, int j, int color, int newColor) {
int m = image.size(), n = image[].size();
if(i< || i>=m || j< || j>=n || image[i][j]!=color) return;//errr..
image[i][j] = newColor;
helper(image, i-, j , color, newColor);
helper(image, i+, j , color, newColor);
helper(image, i , j-, color, newColor);
helper(image, i , j+, color, newColor);
}
};

solution2: 非递归方法;

参考

1. Leetcode_easy_733. Flood Fill;

2. Grandyang;

【Leetcode_easy】733. Flood Fill的更多相关文章

  1. 【LeetCode】733. Flood Fill 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 方法二:BFS 日期 题目地址:ht ...

  2. 【Luogu3457】POW-The Flood(并查集)

    [Luogu3457]POW-The Flood(并查集) 题面 洛谷 题解 我们知道,如果一个点和一个海拔不高于它的点相连 那么连在那个点是更优的,所以考虑按照每个点的海拔排序 既然按照海拔排序,相 ...

  3. LN : leetcode 733 Flood Fill

    lc 733 Flood Fill 733 Flood Fill An image is represented by a 2-D array of integers, each integer re ...

  4. [LeetCode&Python] Problem 733. Flood Fill

    An image is represented by a 2-D array of integers, each integer representing the pixel value of the ...

  5. 733. Flood Fill 简单型染色问题

    [抄题]: An image is represented by a 2-D array of integers, each integer representing the pixel value ...

  6. 【转】ListBox Dock Fill 总是有空隙的问题

    源地址:https://www.cnblogs.com/norsd/p/6359291.html ListBox Dock设置了Fill, Right等 设计界面如己所愿,但是实际运行时,底部总是有不 ...

  7. 733. Flood Fill

    class Solution { public: int szx,szy; vector<vector<int>> floodFill(vector<vector< ...

  8. 【Leetcode_easy】1021. Remove Outermost Parentheses

    problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完

  9. 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers

    problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...

随机推荐

  1. 企业级本地yum源配置方案详解

    因目前企业生产网络禁止联网,对于使用Linux的我们来说,非常不方便,想要使用yum源都很困难,挂dvd又不能完全满足要求,所以自建一个企业级的yum源,定时从公网同步到本地,然后生产网络直接配置在本 ...

  2. MybatisX idea 快速开发插件

    一.idea安装MybatisX 1.按ctrl+alt+s,弹出Settings 2.在plugins中搜索MybatisX,安装即可 3.点击操作重启idea 二.操作说明 1.业务层点击小鸟进入 ...

  3. python pip获取所有已安装的第三包

    pip freeze > requirements.txt # 生成txt 文件 pip install -r requirements.txt # 别人使用时可以直接安装所有的包 [progr ...

  4. spark读文件写mysql(java版)

    package org.langtong.sparkdemo; import com.fasterxml.jackson.databind.ObjectMapper; import org.apach ...

  5. Docker 学习10 Docker的系统资源限制及验证

    一.资源限制 二.内存限制 1.OOME 每一个进程都会有oom_adj(oom计算分数的权重)值,此值越大,oom_score(oom得分)越高,越容易被干掉,因此非常非常重要的容器化应用,一开始就 ...

  6. 【.Net设计模式系列】工作单元(Unit Of Work)模式 ( 二 )

    回顾 在上一篇博客[.Net设计模式系列]仓储(Repository)模式 ( 一 ) 中,通过各位兄台的评论中,可以看出在设计上还有很多的问题,在这里特别感谢 @横竖都溢 @ 浮云飞梦 2位兄台对博 ...

  7. luogu 2934

    同 bzoj3694 需要先求出最短路树 #include <iostream> #include <cstdio> #include <algorithm> #i ...

  8. NetworkX系列教程(10)-算法之二:最小/大生成树问题

    小书匠 Graph 图论  重头戏部分来了,写到这里我感觉得仔细认真点了,可能在NetworkX中,实现某些算法就一句话的事,但是这个算法是做什么的,用在什么地方,原理是怎么样的,不清除,所以,我决定 ...

  9. 使用DOS命令将类库封装成dll

    1.Windows键+R.输入cmd进入DOS 2.使用 cd  加路径找到需要封装成dll的类库文件 3.csc /target:library /out:dll的名字.DLL 需要封装的cs文件

  10. UOJ450 【集训队作业2018】复读机【生成函数】

    题目链接:UOJ EI神仙加强版 既然这题模数是今天日期减去\(7\times 10^5\),那就要赶紧把这题做了. 首先肯定是考虑指数型生成函数,列出来之后使用单位根反演一波. \[\begin{a ...