当前位置:网站首页>278 · 绘制填充
278 · 绘制填充
2022-04-22 06:16:00 【yinhua405】
众所周知,在画图软件中,存在一种名为“填充”的功能。
“填充”功能可以在你点击鼠标后,将一块拥有相同颜色的区域完全被你选中的颜色覆盖,如下图:

现在,你将实现一个算法来模拟这个功能。
你将得到一个二维数组board,以及三个整数x,y,newColor。board[i][j] 代表画板第i行第j列的像素点的颜色,不同的颜色将用不同的整数表示。x与y代表你将要点击画板上第x行第y列的像素点,newColor则代表你将用于“填充”的颜色。
你需要直接在原数组board上进行操作,评测程序将检查数组board是否被修改正确。
0≤newColor,boardij≤50 \leq newColor, board_{ij} \leq 50≤newColor,boardij≤5
1≤board.length≤10001 \leq board.length \leq 10001≤board.length≤1000
1≤board[0].length≤10001 \leq board[0].length \leq 10001≤board[0].length≤1000
0≤x<board.length0 \leq x < board.length0≤x<board.length
0≤y<board[0].length0 \leq y < board[0].length0≤y<board[0].length
样例
样例 1:
输入:
board = [[1, 0], [0, 1]]
x = 1
y = 1
newColor = 2
输出:
[[1, 0], [0, 2]]
解释:
你不需要返回任何值,但是数组board应该被修改为[[1, 0], [0, 2]]。

样例 2:
输入:
board = [[1, 0, 2], [1, 0, 0], [3, 1, 0]]
x = 0
y = 1
newColor = 5
输出:
[[1, 5, 2], [1, 5, 5], [3, 1, 5]]
解释:
你不需要返回任何值,但是数组board应该被修改为[[1, 5, 2], [1, 5, 5], [3, 1, 5]]。

class Solution {
public:
/**
* @param board: a two-dimensional array of colors
* @param x: the abscissa of the click position
* @param y: the ordinate of the click position
* @param newColor: an integer that represent a new color
* @return: nothing
*/
void fill(vector<vector<int>> &board, int x, int y, int newColor,int num)
{
if(x < 0 || x >= board.size() )
{
return;
}
if(y <0 || y >= board[0].size())
{
return;
}
if( board[x][y] != num)
{
return;
}
board[x][y] = newColor;
fill(board, x+1, y, newColor,num);
fill(board, x-1, y, newColor,num);
fill(board, x, y+1, newColor,num);
fill(board, x, y-1, newColor,num);
}
void paintFill(vector<vector<int>> &board, int x, int y, int newColor) {
// write your code here.
fill(board, x, y, newColor,board[x][y]);
}
};
版权声明
本文为[yinhua405]所创,转载请带上原文链接,感谢
https://blog.csdn.net/yinhua405/article/details/121943910
边栏推荐
- 桥接模式下主机ping不通虚拟机
- Beyond Compare“授权密钥已被吊销”的解决办法
- Define a student class 1 to get the student's name: get_ Name() return type: STR 2 get student's age: get_ Age() return type: int 3 returns the highest score among the three subjects. get_ course()
- Unknown graphics extension:. 1 jpg. }
- instanceof的使用说明及实例讲解
- Process of stepping on the pit in the flutter environment
- [number theory] prime number (V): Mason prime number (lucas_lehmer decision method)
- C语言 | 位运算符
- 树+二叉树 详解 详解 +Top-k问题
- Redis進階
猜你喜欢

Binary tree chain structure operation leetcode + Niuke (detailed explanation)

Build ES6 development environment and compile in real time

桥接模式下主机ping不通虚拟机

vivado生成和调用edf网表文件

Win10 modify command line default font

八大排序的思想及其代码

In the process of class loading, the allocation area of class variables is different from that of instance variables

字节暑期实习一面——20220304

Beyond compare solution to "authorization key has been revoked"

win10修改命令行默认字体
随机推荐
虚拟机磁盘空间缩小
小游戏——三子棋
(6) DCL and DML syntax of SQL Server
Two algorithm questions for Microsoft intern interview -- 20220119
【数论】同余(二):逆元
Some mechanisms of synchronized lock optimization (lock upgrade)
顺序表 增删查(找)
Design a circle class with private member radius representing radius and function get_ Radius () is used to obtain the radius and area () is used to calculate the area of the circle; (2) Define a tabl
Redis进阶
The thought and code of eight sorting
链表难题记录一
[number theory] congruence (III): univariate linear congruence equation
Redis進階
Quartus II防止信号被综合
(2) Basic configuration of SQL server and connection to SQL server using Navicat
Choose any novel website, crawl any novel and save it in the form of Notepad.
Codeforces Round #610 (Div. 2)
在类加载的过程中,类变量的分配区域和实例变量的分配区域不一样
Cannot find interface mapping after updating HDF
[number theory] prime number (I): basic concepts, properties, conjectures and theorems