1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/旋转链表 [rotate-list].html

28 lines
903 B
HTML
Raw Normal View History

2022-03-27 20:56:26 +08:00
<p>给你一个链表的头节点 <code>head</code> ,旋转链表,将链表每个节点向右移动&nbsp;<code>k</code><em>&nbsp;</em>个位置。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/rotate1.jpg" style="width: 450px;" />
<pre>
<strong>输入:</strong>head = [1,2,3,4,5], k = 2
<strong>输出:</strong>[4,5,1,2,3]
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/roate2.jpg" style="width: 305px; height: 350px;" />
<pre>
<strong>输入:</strong>head = [0,1,2], k = 4
<strong>输出:</strong>[2,0,1]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>链表中节点的数目在范围 <code>[0, 500]</code></li>
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
<li><code>0 &lt;= k &lt;= 2 * 10<sup>9</sup></code></li>
</ul>