您的位置:首页 > 编程语言 > Python开发

【LintCode 简单】372. 在O(1)时间复杂度删除链表节点

2018-01-15 16:04 435 查看
1.问题描述:给定一个单链表中的一个等待被删除的节点(非表头或表尾)。请在在O(1)时间复杂度删除该链表节点。2.样例:Linked list is 
1->2->3->4
, and given node 
3
,delete the node in place 
1->2->4。
3.代码:
"""Definition of ListNodeclass ListNode(object):def __init__(self, val, next=None):self.val = valself.next = next"""class Solution:"""@param: node: the node in the list should be deletedt@return: nothing"""def deleteNode(self, node):# write your code herenode.val=node.next.valnode.next=node.next.next
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LintCode Python 单链表