LintCode Q372 Delete Node in the Middle of Singly Linked List in Python

  • Jinhai ZHOU
  • 2 Minutes
  • 2017年2月25日
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""
Definition of ListNode
class ListNode(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
"""
class Solution:
# @param node: the node in the list should be deleted
# @return: nothing
def deleteNode(self, node):
# write your code here
previous = node
while node.next:
node.val = node.next.val
previous = node
node = node.next
previous.next = None
知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。