title: Intersection of two linked lists without duplicities
body: <p>Given two sorted linked lists, where the result should be intersection without duplicities.</p>
  <ul>
  <li>Creating of new nodes is not allowed.</li>
  <li>The resulting list will be composed of the elements of the original lists.</li>
  </ul>
  <p><em>Inputs are two lists separated by empty line</em>:</p>
  <p><em>L1</em> -&gt; 2 3 3 4 4 4 5</p>
  <p><em>L2</em> -&gt; 3 4 5 6 7</p>
  <p><em>Result</em> -&gt; 3 4 5</p>
  <p>I have my solution below, but creating new node in <strong>IntersectionDestruct</strong> function.</p>
  <p>Is there any simple way how to change <em>IntersectionDestruct</em> function with the logic of not creating any new node?</p>
  <pre><code>class Node:
  def __init__(self, data, next = None):
      self.data = data
      self.next = next
  
  def PrintLinkedList( p ):
      print( &quot;Result:&quot;, end=&quot; &quot; )
      while p!=None:
          print( p.data, end=&quot; &quot; )
          p = p.next
      print(&quot;.&quot;)
  
  def ReadLinkedList():
      first = None
      last = None
      r = input()
      while r!=&quot;&quot;:
          row = r.split()
          if len(row)==0:
              break
          for s in row:
              p = Node(int(s),None)
              if first==None:
                  first = p
              else:
                  last.next = p
              last = p
          r = input()
  return first
  
  def LLIntersection(a, b):
      head = tail = None
  
      while a and b:
          if a.data == b.data:
              if head is None:
                  head = Node(a.data, head)
                  tail = head
              else:
                  tail.next = Node(a.data, tail.next)
                  tail = tail.next
  
              a = a.next
              b = b.next
  
          # advance the smaller list
          elif a.data &lt; b.data:
              a = a.next
          else:
              b = b.next
      return head    
  </code></pre>