#!/usr/bin/env python3

__author__ = 'Wei Mu'

class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        if head == None or head.next == None:
            return head
        
        ans = ListNode(0)
        
        ans_chain = ans
        
        p1 = head
        p2 = head.next
        temp = None
        
        while p2 != None:
            if p1.val != temp and p1.val != p2.val:
                ans_chain.next = p1
                ans_chain = ans_chain.next
                
            
            temp = p1.val
            p1 = p1.next
            p2 = p2.next
            
            ans_chain.next = None
            
        if temp != p1.val:
            ans_chain.next = p1
        
        return ans.next
