Skip to content

LeetCode

237. 删除链表中的节点

image.png

思路

image.pngimage.png

题解

typescript
/**
 * 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) {
    // 将下一个节点val给要删除的节点
    node.val = node.next.val
    // 改变next指向,变相删除
    node.next = node.next.next
};

image.png

https://leetcode.cn/problems/delete-node-in-a-linked-list/solutions/47948/tu-jie-shan-chu-lian-biao-zhong-de-jie-dian-python/