Leetcode 237. Delete Node in a Linked List
给一个节点,在链表中删除这个节点,不返回任何值。
代码如下:
class Solution(object):
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
pre = node
while(node.next != None):
node.val = node.next.val
pre = node
node = node.next
pre.next = None
别人的代码如此简洁快捷:
class Solution(object):
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
temp = node.next
node.val = node.next.val
node.next = node.next.next
temp = None
转载:https://blog.csdn.net/vancooler/article/details/101228527
查看评论