Simple python solution in place, >65%


  • 0
    S
    def deleteDuplicates(self, head):
         """
         :type head: ListNode
         :rtype: ListNode
         """
         if not head:
             return head
             
         p1 = head
         p2 = head.next
         while (p1 and p2): 
             if p1.val == p2.val:
                 p1.next = p2.next
                 p2.next = None
                 p2 = p1.next
             else:
                 p1 = p1.next
                 p2 = p2.next
         
         return head

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.