Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.
Example 1:
Input: head = [1,1,2]
Output: [1,2]
Example 2:
Input: head = [1,1,2,3,3]
Output: [1,2,3]
Solution:
class Solution(object):
def deleteDuplicates(self, head):
if not head:
return head
cur = head # 指针,用来串联不重复的元素
while cur.next:
if cur.val == cur.next.val:
cur.next = cur.next.next
else:
cur = cur.next
return head
标签:head,cur,Duplicates,list,List,next,Output,Sorted,Input
From: https://www.cnblogs.com/artwalker/p/17495966.html