title: Python linked list remove duplicate
body: <p>I am trying to write a code to remove duplicates from a sorted linked list "head". My code below always returns the last duplicate if the list ends with a duplicate. for e.g. <code>[1,2,2,3,3]</code> will return <code>[1,2,3,3]</code>. I can't figure out why. Does anyone have an idea?</p>
  
  <pre><code>class Solution(object):
      def deleteDuplicates(self, head):
          """
          :type head: ListNode
          :rtype: ListNode
          """
  
          if not head:
              return head
  
          l1=newhead=ListNode(head.val)
          head=head.next
  
  
          while head:
              if head.val!=l1.val:
                  l1.next=head
                  l1=l1.next
              head=head.next
  
          return newhead
  </code></pre>