题目浅析

  • 想查看原题可以点击题目链接

  • 简单地说,就是在不给链表头的情况下,仅给要删除的节点,如何实现删除。(链表长度至少为 2,且删除节点不在队尾)

思路分享

代码解答(强烈建议自行解答后再看)

  • 参考题解
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None

class Solution:
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
node.val = node.next.val
node.next = node.next.next