【Leetcode_easy】733. Flood Fill
problem
题意:图像处理中的泛洪填充算法,常见的有四邻域像素填充法、八邻域像素填充法、基于扫描线的像素填充法,实现方法分为递归与非递归(基于栈)。
泛洪填充算法原理:从某个像素点开始,将封闭区域内的所有此像素值位置的元素填充为新颜色。
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的更多相关文章
- 【LeetCode】733. Flood Fill 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 方法二:BFS 日期 题目地址:ht ...
- 【Luogu3457】POW-The Flood(并查集)
[Luogu3457]POW-The Flood(并查集) 题面 洛谷 题解 我们知道,如果一个点和一个海拔不高于它的点相连 那么连在那个点是更优的,所以考虑按照每个点的海拔排序 既然按照海拔排序,相 ...
- 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 ...
- [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 ...
- 733. Flood Fill 简单型染色问题
[抄题]: An image is represented by a 2-D array of integers, each integer representing the pixel value ...
- 【转】ListBox Dock Fill 总是有空隙的问题
源地址:https://www.cnblogs.com/norsd/p/6359291.html ListBox Dock设置了Fill, Right等 设计界面如己所愿,但是实际运行时,底部总是有不 ...
- 733. Flood Fill
class Solution { public: int szx,szy; vector<vector<int>> floodFill(vector<vector< ...
- 【Leetcode_easy】1021. Remove Outermost Parentheses
problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完
- 【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 ...
随机推荐
- 第119题:杨辉三角II
一. 问题描述 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 3 输出: [1,3,3,1] 二. 解题思路 ...
- 进程 multiprocessing Process join Lock Queue
多道技术 1.空间上的复用 多个程序公用一套计算机硬件 2.时间上的复用 cpu 切换程序+保存程序状态 1.当一个程序遇到IO操作,操作系统会剥夺该程序的cpu执行权限(提高了cpu的利用率,并且不 ...
- STM32的指令周期
在keil中编程时,写了一行代码,然后就想知道,执行这句C代码需要多长时间. 时钟周期在这就不解释了,频率的倒数. 指令周期,个人理解就是cpu执行一条汇编指令所需要的时间. 我们知道cm3使用的三级 ...
- Maximum Subarray II
Given an array of integers, find two non-overlapping subarrays which have the largest sum. The numbe ...
- PostgreSQL 使用PG_Rman进行物理备份
背景 在Oracle下我们可以使用rman进行物理备份,支持数据库的全量.增量.归档的备份模式而PostgreSQL作为开源数据库,近些时间来也一直向商业版数据库看齐,也推出了开源功工具pg_rman ...
- list, vector, map, set 区别与用法比较
List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]. Vector对于随机 ...
- 【原创】go语言学习(十三)struct介绍2
目录: 方法的定义 函数和方法的区别 值类型和指针类型 面向对象和继承 结构体和json序列化 方法的定义 1.和其他语言不一样,Go的方法采⽤用另外一种方式实现. package main impo ...
- spark map函数中使用println无法输出
问题 // 每个点为hardData中的一个Array val hardData = spark.read.textFile(args(0)).rdd .map(_.split(" &quo ...
- nmon服务器性能结果报告分析
一.nmon命令 ./nmon_x86_64_centos7 -f -s 10 -c 60 -m ./log/ 命令的含义是: -f :按标准格式输出文件名称:<hostname>_YY ...
- Ubuntu 14.04 indigo 相关依赖
sudo apt-get install libbullet-dev sudo apt-get install ros-indigo-bfl sudo apt-get install libsdl-d ...