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. Git报错:Your branch is up to date with 'origin/master'.

    Git在提交的时候报错 Your branch is up to date with 'origin/master'. 报错 Your branch is up to date with 'origi ...

  2. vue2 路由,运动

  3. 15 Vue计算属性和侦听器

    计算属性 模板内的表达式非常便利,但是设计它们的初衷是用于简单运算的. 在模板中放入太多的逻辑会让模板过重且难以维护.例如: split = 字符中间空格分割, reverse= 反转 join('' ...

  4. idea在src/main/java下新建包后项目中只显示src/main,后面的东西不显示,但在本地磁盘中是存在的

    去掉图中的勾

  5. git删除指定commit

    1.使用git log 命令,查看已提交的记录.例如红色圈出的commit是本次要删除的commit. 2.先找到此次提交之前的一次提交的commit 1d6b81b138f89735265900b9 ...

  6. 009——C#全局变量定义

    (一)窗体二定义,static静态 public static byte[] waveform_data = { }; // 数据,在串口接收中变化 public static bool wavefo ...

  7. bzoj 2563: 阿狸和桃子的游戏 贪心

    这个真的好巧妙啊~ 如果只考虑点权的话显然直接按照权值大小排序即可. 但是加入了边权,就有了一个决策的问题. 于是,我们将边权分一半,分给两个端点. 如果一个人拿了两个端点,则边权都会加上. 否则,边 ...

  8. Tomcat 解决jvm中文乱码,控制台乱码

    解决方法 打开tomcat/conf/目录 修改logging.properties 找到 java.util.logging.ConsoleHandler.encoding = utf-8 这行 更 ...

  9. PHP全栈学习笔记29

    前言 这一章主要讲一讲PHP的背景,优势,PHP的环境搭建,书写和调式简单的PHP代码,如何解决简单的PHP错误等. 目录结构 PHP简介 PHP是面向对象,指令式编程,设计者是 拉斯姆斯·勒多夫 出 ...

  10. postgresql 创建索引:ERROR: operator class "gin_trgm_ops" does not exist for access method "gin"

    g_trgm is an extension, so: CREATE EXTENSION pg_trgm; If you get the following error ERROR: could no ...