mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-07 00:11:41 +08:00
50 lines
2.5 KiB
HTML
50 lines
2.5 KiB
HTML
<p>有一幅以 <code>m x n</code> 的二维整数数组表示的图画 <code>image</code> ,其中 <code>image[i][j]</code> 表示该图画的像素值大小。你也被给予三个整数 <code>sr</code> , <code>sc</code> 和 <code>color</code> 。你应该从像素 <code>image[sr][sc]</code> 开始对图像进行上色 <strong>填充</strong> 。</p>
|
||
|
||
<p>为了完成 <strong>上色工作</strong>:</p>
|
||
|
||
<ol>
|
||
<li>从初始像素开始,将其颜色改为 <code>color</code>。</li>
|
||
<li>对初始坐标的 <strong>上下左右四个方向上</strong> 相邻且与初始像素的原始颜色同色的像素点执行相同操作。</li>
|
||
<li>通过检查与初始像素的原始颜色相同的相邻像素并修改其颜色来继续 <strong>重复</strong> 此过程。</li>
|
||
<li>当 <strong>没有</strong> 其它原始颜色的相邻像素时 <strong>停止</strong> 操作。</li>
|
||
</ol>
|
||
|
||
<p>最后返回经过上色渲染 <strong>修改</strong> 后的图像 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<p><img src="https://assets.leetcode.com/uploads/2021/06/01/flood1-grid.jpg" /></p>
|
||
|
||
<div class="example-block"><strong>输入:</strong>image = [[1,1,1],[1,1,0],[1,0,1]],sr = 1, sc = 1, color = 2</div>
|
||
|
||
<div class="example-block"><strong>输出:</strong>[[2,2,2],[2,2,0],[2,0,1]]</div>
|
||
|
||
<div class="example-block"><b>解释:</b>在图像的正中间,坐标 <code>(sr,sc)=(1,1)</code> (即红色像素),在路径上所有符合条件的像素点的颜色都被更改成相同的新颜色(即蓝色像素)。</div>
|
||
|
||
<div class="example-block">注意,右下角的像素 <strong>没有</strong> 更改为2,因为它不是在上下左右四个方向上与初始点相连的像素点。</div>
|
||
|
||
<div class="example-block"> </div>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<div class="example-block"><strong>输入:</strong>image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0</div>
|
||
|
||
<div class="example-block"><strong>输出:</strong>[[0,0,0],[0,0,0]]</div>
|
||
|
||
<div class="example-block"><strong>解释:</strong>初始像素已经用 0 着色,这与目标颜色相同。因此,不会对图像进行任何更改。</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>m == image.length</code></li>
|
||
<li><code>n == image[i].length</code></li>
|
||
<li><code>1 <= m, n <= 50</code></li>
|
||
<li><code>0 <= image[i][j], color < 2<sup>16</sup></code></li>
|
||
<li><code>0 <= sr < m</code></li>
|
||
<li><code>0 <= sc < n</code></li>
|
||
</ul>
|