首页 > 其他 > 详细

237. 删除链表中的节点

时间:2020-05-09 14:57:10      阅读:38      评论:0      收藏:0      [点我收藏+]

技术分享图片
技术分享图片
技术分享图片
技术分享图片

方法一:

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

方法二:

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

237. 删除链表中的节点

原文:https://www.cnblogs.com/panweiwei/p/12857254.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!