mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
138 lines
3.2 KiB
HTML
138 lines
3.2 KiB
HTML
<p>给你两个 <strong>正整数 </strong><code>n</code> 和 <code>k</code>。有 <code>n</code> 个编号从 <code>0</code> 到 <code>n - 1</code> 的孩子按顺序从左到右站成一队。</p>
|
||
|
||
<p>最初,编号为 0 的孩子拿着一个球,并且向右传球。每过一秒,拿着球的孩子就会将球传给他旁边的孩子。一旦球到达队列的 <strong>任一端 </strong>,即编号为 0 的孩子或编号为 <code>n - 1</code> 的孩子处,传球方向就会<strong> 反转 </strong>。</p>
|
||
|
||
<p>返回 <code>k</code> 秒后接到球的孩子的编号。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong><span class="example-io">n = 3, k = 5</span></p>
|
||
|
||
<p><strong>输出:</strong><span class="example-io">1</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<th>经过的时间</th>
|
||
<th>孩子队列</th>
|
||
</tr>
|
||
<tr>
|
||
<td><code>0</code></td>
|
||
<td><code>[<u>0</u>, 1, 2]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>1</code></td>
|
||
<td><code>[0, <u>1</u>, 2]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>2</code></td>
|
||
<td><code>[0, 1, <u>2</u>]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>3</code></td>
|
||
<td><code>[0, <u>1</u>, 2]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>4</code></td>
|
||
<td><code>[<u>0</u>, 1, 2]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>5</code></td>
|
||
<td><code>[0, <u>1</u>, 2]</code></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong><span class="example-io">n = 5, k = 6</span></p>
|
||
|
||
<p><strong>输出:</strong><span class="example-io">2</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<th>经过的时间</th>
|
||
<th>孩子队列</th>
|
||
</tr>
|
||
<tr>
|
||
<td><code>0</code></td>
|
||
<td><code>[<u>0</u>, 1, 2, 3, 4]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>1</code></td>
|
||
<td><code>[0, <u>1</u>, 2, 3, 4]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>2</code></td>
|
||
<td><code>[0, 1, <u>2</u>, 3, 4]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>3</code></td>
|
||
<td><code>[0, 1, 2, <u>3</u>, 4]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>4</code></td>
|
||
<td><code>[0, 1, 2, 3, <u>4</u>]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>5</code></td>
|
||
<td><code>[0, 1, 2, <u>3</u>, 4]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>6</code></td>
|
||
<td><code>[0, 1, <u>2</u>, 3, 4]</code></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 3:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong><span class="example-io">n = 4, k = 2</span></p>
|
||
|
||
<p><strong>输出:</strong><span class="example-io">2</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<table>
|
||
<tbody>
|
||
<tr>
|
||
<th>经过的时间</th>
|
||
<th>孩子队列</th>
|
||
</tr>
|
||
<tr>
|
||
<td><code>0</code></td>
|
||
<td><code>[<u>0</u>, 1, 2, 3]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>1</code></td>
|
||
<td><code>[0, <u>1</u>, 2, 3]</code></td>
|
||
</tr>
|
||
<tr>
|
||
<td><code>2</code></td>
|
||
<td><code>[0, 1, <u>2</u>, 3]</code></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>2 <= n <= 50</code></li>
|
||
<li><code>1 <= k <= 50</code></li>
|
||
</ul>
|