判断下一个元素与前一个元素的关系,如果相等,就把第三个值赋给第二个值,如果不相等,就从第二个元素从新判断
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
l = head
if l==None or l.next == None:
return head
while l.next:
if l.val == l.next.val:
l.next =l.next.next
else:
l = l.next
return head
来源:CSDN
作者:李如花
链接:https://blog.csdn.net/lvjiwei001/article/details/104727692