input: Write a function to remove duplicates from a linked list.
  assert convert_to_list(remove_duplicates(create_linked_list([1, 2, 3, 3, 4, 4, 5]))) == [1, 2, 3, 4, 5]
  assert convert_to_list(remove_duplicates(create_linked_list([1, 1, 1, 1, 1]))) == [1]
  assert convert_to_list(remove_duplicates(create_linked_list([5, 4, 3, 2, 1, 2, 3, 4, 5]))) == [5, 4, 3, 2, 1]
output: class ListNode:
      def __init__(self, val=0, next=None):
          self.val = val
          self.next = next
  
  def create_linked_list(arr):
      if not arr:
          return None
      head = ListNode(arr[0])
      current = head
      for val in arr[1:]:
          current.next = ListNode(val)
          current = current.next
      return head
  
  def convert_to_list(head):
      result = []
      current = head
      while current:
          result.append(current.val)
          current = current.next
      return result
  
  def remove_duplicates(head):
      if not head:
          return head
  
      current = head
      while current and current.next:
          if current.val == current.next.val:
              current.next = current.next.next
          else:
              current = current.next
      return head