We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Difficulty: 中等
Related Topics: 链表
有一个单链表的 head,我们想删除它其中的一个节点 node。
head
node
给你一个需要删除的节点 node 。你将 无法访问 第一个节点 head。
链表的所有值都是 唯一的,并且保证给定的节点 node 不是链表中的最后一个节点。
删除给定的节点。注意,删除节点并不是指从内存中删除它。这里的意思是:
自定义测试:
示例 1:
输入:head = [4,5,1,9], node = 5 输出:[4,1,9] 解释:指定链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9
示例 2:
输入:head = [4,5,1,9], node = 1 输出:[4,5,9] 解释:指定链表中值为 1 的第三个节点,那么在调用了你的函数之后,该链表应变为 4 -> 5 -> 9
提示:
[2, 1000]
-1000 <= Node.val <= 1000
Language: JavaScript
/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } */ /** * @param {ListNode} node * @return {void} Do not return anything, modify node in-place instead. */ // 和下一个节点交换 var deleteNode = function(node) { node.val = node.next.val node.next = node.next.next };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
237. 删除链表中的节点
Description
Difficulty: 中等
Related Topics: 链表
有一个单链表的
head
,我们想删除它其中的一个节点node
。给你一个需要删除的节点
node
。你将 无法访问 第一个节点head
。链表的所有值都是 唯一的,并且保证给定的节点
node
不是链表中的最后一个节点。删除给定的节点。注意,删除节点并不是指从内存中删除它。这里的意思是:
node
前面的所有值顺序相同。node
后面的所有值顺序相同。自定义测试:
head
和要给出的节点node
。node
不应该是链表的最后一个节点,而应该是链表中的一个实际节点。示例 1:
示例 2:
提示:
[2, 1000]
-1000 <= Node.val <= 1000
node
是 链表中的节点 ,且 不是末尾节点Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: