美文网首页
237. Delete Node in a Linked Lis

237. Delete Node in a Linked Lis

作者: jluemmmm | 来源:发表于2021-11-29 17:58 被阅读0次

删除链表中的节点,用于删除单链表中某个特定节点。在设计函数时需要注意,无法访问链表头节点head,只能直接访问要被删除的节点,需要删除的节点不是末尾节点。

  • 时间复杂度O(1),空间复杂度O(1)
  • Runtime: 76 ms, faster than 93.83%
  • Memory Usage: 40.8 MB, less than 22.09%
/**
 * 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;
};

相关文章

网友评论

      本文标题:237. Delete Node in a Linked Lis

      本文链接:https://www.haomeiwen.com/subject/fuulxrtx.html