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)/反转链表 II [reverse-linked-list-ii].html
2022-03-29 12:43:11 +08:00

32 lines
1.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

给你单链表的头指针 <code>head</code> 和两个整数 <code>left</code><code>right</code> ,其中 <code>left <= right</code> 。请你反转从位置 <code>left</code> 到位置 <code>right</code> 的链表节点,返回 <strong>反转后的链表</strong>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/rev2ex2.jpg" style="width: 542px; height: 222px;" />
<pre>
<strong>输入:</strong>head = [1,2,3,4,5], left = 2, right = 4
<strong>输出:</strong>[1,4,3,2,5]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>head = [5], left = 1, right = 1
<strong>输出:</strong>[5]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>链表中节点数目为 <code>n</code></li>
<li><code>1 <= n <= 500</code></li>
<li><code>-500 <= Node.val <= 500</code></li>
<li><code>1 <= left <= right <= n</code></li>
</ul>
<p> </p>
<p><strong>进阶:</strong> 你可以使用一趟扫描完成反转吗?</p>