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. Python之Linux命令

    1.查看当前文件路径  :  pwd LangYingdeMacBook-Pro:Users langying$ pwd /Users 2.切换目录 cd 例如:切换到根目录  : cd /   回到 ...

  2. Vue获取后端数据 渲染页面后跳转

    主页面 <template> <div> <ul v-for="item in courseList"> <router-link :to ...

  3. pycharm连接不上mysql数据库的解决办法

    问题描述 环境:ubuntu18.04,mysql5.7 今天在ubuntu下使用pycharm连接mysql,发现连接不上 这不是缺少驱动吗?下载之! 下好之后点进去 连接 点击test conne ...

  4. HDU-1028-Ignatius and the Princess III(母函数)

    链接: https://vjudge.net/problem/HDU-1028 题意: "Well, it seems the first problem is too easy. I wi ...

  5. 072_查看所有虚拟机磁盘使用量以及 CPU 使用量信息

    #!/bin/bashvirt-df #虚拟机磁盘使用量read -n1 "按任意键继续" keyvirt-top # CPU 使用量

  6. 富文本编辑器+可粘贴word内容

    Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧? 我希望打开文档doc直接复制粘贴到富文本编辑器,直接发布 感觉这个似乎很困难 ...

  7. NetworkX系列教程(10)-算法之三:关键路径问题

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

  8. c++ yaml-cpp 安装

    环境: Ubuntu14. 下载cmake(我使用的是3.1.0) https://cmake.org/files/v3.1/ tar -xvf cmake--Linux-x86_64.tar.gz ...

  9. ElasticSearch java客户端更新时出现的错误:NoNodeAvailableException[None of the configured nodes are available

    下午尝试 用ElasticSearch  的java客户端去做数据检索工作,测试了一下批量更新,代码如下: public static void bulkUpdateGoods(List<Goo ...

  10. C语言中的多线程

    原文:https://www.cnblogs.com/yorkyang/p/7804733.html 线程的优点: 减少系统调度开销,不占有独立的资源,切换速度快,执行效率高. 线程间通信方便,可共享 ...