# Given a sorted linked list, delete all duplicates such that each element appear only once.
#
# For example,
# Given 1->1->2, return 1->2.
# Given 1->1->2->3->3, return 1->2->3.
class ListNode():
def __init__(self, x):
self.val = x
self.next = None
class Solution():
def deleteDuplicates(self, head):
cur = head
while cur:
while cur.next and cur.next.val == cur.val:
cur.next = cur.next.next
cur = cur.next
return head
if __name__ == "__main__":
head, head.next, head.next.next, head.next.next.next, head.next.next.next.next \
= ListNode(1), ListNode(1), ListNode(2), ListNode(3), ListNode(3)
assert Solution().deleteDuplicates(head).val == 1