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)/删除链表中的节点 [delete-node-in-a-linked-list].html
2022-03-29 12:43:11 +08:00

32 lines
1.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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.

<p>请编写一个函数,用于 <strong>删除单链表中某个特定节点</strong> 。在设计函数时需要注意,你无法访问链表的头节点&nbsp;<code>head</code> ,只能直接访问 <strong>要被删除的节点</strong></p>
<p>题目数据保证需要删除的节点 <strong>不是末尾节点</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/09/01/node1.jpg" style="height: 215px; width: 300px;" />
<pre>
<strong>输入:</strong>head = [4,5,1,9], node = 5
<strong>输出:</strong>[4,1,9]
<strong>解释:</strong>指定链表中值为&nbsp;5&nbsp;的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -&gt; 1 -&gt; 9
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/09/01/node2.jpg" style="height: 236px; width: 300px;" />
<pre>
<strong>输入:</strong>head = [4,5,1,9], node = 1
<strong>输出:</strong>[4,5,9]
<strong>解释:</strong>指定链表中值为&nbsp;1&nbsp;的第三个节点,那么在调用了你的函数之后,该链表应变为 4 -&gt; 5 -&gt; 9</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>链表中节点的数目范围是 <code>[2, 1000]</code></li>
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
<li>链表中每个节点的值都是 <strong>唯一</strong></li>
<li>需要删除的节点 <code>node</code><strong>链表中的节点</strong> ,且 <strong>不是末尾节点</strong></li>
</ul>