1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/图像渲染 [flood-fill].html
2022-03-29 12:43:11 +08:00

41 lines
2.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>有一幅以&nbsp;<code>m x n</code>&nbsp;的二维整数数组表示的图画&nbsp;<code>image</code>&nbsp;,其中&nbsp;<code>image[i][j]</code>&nbsp;表示该图画的像素值大小。</p>
<p>你也被给予三个整数 <code>sr</code> ,&nbsp; <code>sc</code><code>newColor</code> 。你应该从像素&nbsp;<code>image[sr][sc]</code>&nbsp;开始对图像进行 上色<strong>填充</strong></p>
<p>为了完成<strong> 上色工作</strong> ,从初始像素开始,记录初始坐标的 <strong>上下左右四个方向上</strong> 像素值与初始坐标相同的相连像素点,接着再记录这四个方向上符合条件的像素点与他们对应 <strong>四个方向上</strong> 像素值与初始坐标相同的相连像素点,……,重复该过程。将所有有记录的像素点的颜色值改为&nbsp;<code>newColor</code>&nbsp;</p>
<p>最后返回 <em>经过上色渲染后的图像&nbsp;</em></p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/06/01/flood1-grid.jpg" /></p>
<pre>
<strong>输入:</strong> image = [[1,1,1],[1,1,0],[1,0,1]]sr = 1, sc = 1, newColor = 2
<strong>输出:</strong> [[2,2,2],[2,2,0],[2,0,1]]
<strong>解析:</strong> 在图像的正中间,(坐标(sr,sc)=(1,1)),在路径上所有符合条件的像素点的颜色都被更改成2。
注意右下角的像素没有更改为2因为它不是在上下左右四个方向上与初始点相连的像素点。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong> image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, newColor = 2
<strong>输出:</strong> [[2,2,2],[2,2,2]]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == image.length</code></li>
<li><code>n == image[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 50</code></li>
<li><code>0 &lt;= image[i][j], newColor &lt; 2<sup>16</sup></code></li>
<li><code>0 &lt;= sr &lt;&nbsp;m</code></li>
<li><code>0 &lt;= sc &lt;&nbsp;n</code></li>
</ul>