删除链表中重复的节点
在一个排序的链表中,如何删除重复的节点?
class LinkedList:
def __init__(self, val=None):
self.val = val
self.next = None
class Solution:
def delete_same_node(self, root):
head = LinkedList(-1)
head.next = root
node = root
while node:
if not node.next:
break
if node.next.val != node.val:
node = node.next
continue
next_node = node.next
while next_node:
if not next_node.next:
break
if next_node.next.val == next_node.val:
next_node = next_node.next
else:
break
node.next = next_node.next
next_node.next = None
node = node.next
return head.next