1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-27 18:50:26 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/N 天后的牢房 [prison-cells-after-n-days].html

50 lines
1.7 KiB
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>监狱中 <code>8</code> 间牢房排成一排,每间牢房可能被占用或空置。</p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>每天,无论牢房是被占用或空置,都会根据以下规则进行变更:</p>
2022-03-27 20:46:41 +08:00
<ul>
<li>如果一间牢房的两个相邻的房间都被占用或都是空的,那么该牢房就会被占用。</li>
<li>否则,它就会被空置。</li>
</ul>
2023-12-09 18:42:21 +08:00
<p><strong>注意</strong>:由于监狱中的牢房排成一行,所以行中的第一个和最后一个牢房不存在两个相邻的房间。</p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>给你一个整数数组 <code>cells</code> ,用于表示牢房的初始状态:如果第 <code>i</code> 间牢房被占用,则 <code>cell[i]==1</code>,否则 <code>cell[i]==0</code> 。另给你一个整数 <code>n</code></p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>请你返回 <code>n</code> 天后监狱的状况(即,按上文描述进行 <code>n</code> 次变更)。</p>
2022-03-27 20:46:41 +08:00
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong>cells = [0,1,0,1,1,0,0,1], n = 7
2022-03-27 20:46:41 +08:00
<strong>输出:</strong>[0,0,1,1,0,0,0,0]
2023-12-09 18:42:21 +08:00
<strong>解释:</strong>下表总结了监狱每天的状况:
2022-03-27 20:46:41 +08:00
Day 0: [0, 1, 0, 1, 1, 0, 0, 1]
Day 1: [0, 1, 1, 0, 0, 0, 0, 0]
Day 2: [0, 0, 0, 0, 1, 1, 1, 0]
Day 3: [0, 1, 1, 0, 0, 1, 0, 0]
Day 4: [0, 0, 0, 0, 0, 1, 0, 0]
Day 5: [0, 1, 1, 1, 0, 1, 0, 0]
Day 6: [0, 0, 1, 0, 1, 1, 0, 0]
Day 7: [0, 0, 1, 1, 0, 0, 0, 0]
</pre>
<p><strong>示例 2</strong></p>
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong>cells = [1,0,0,1,0,0,1,0], n = 1000000000
2022-03-27 20:46:41 +08:00
<strong>输出:</strong>[0,0,1,1,1,1,1,0]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
2023-12-09 18:42:21 +08:00
<ul>
2022-03-27 20:46:41 +08:00
<li><code>cells.length == 8</code></li>
2023-12-09 18:42:21 +08:00
<li><code>cells[i]</code><code>0</code><code>1</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>