title: Removing elements from singly-linked list (C++)
body: <p>Given a singly-linked list of integers l and an integer k, how can I remove all elements from list l that have a value of k? Preferably in O(n) time. Here's what I have:</p>
  
  <pre><code>// Definition for singly-linked list:
  // template&lt;typename T&gt;
  // struct ListNode {
  //   ListNode(const T &amp;v) : value(v), next(nullptr) {}
  //   T value;
  //   ListNode *next;
  // };
  //
  ListNode&lt;int&gt; * removeKFromList(ListNode&lt;int&gt; * l, int k) {
  ListNode iterator = l;
  while(iterator != NULL)
    {
      if(iterator-&gt;value == k)
      {
  
      }
      iterator = iterator-&gt;next;
    }
  }
  </code></pre>
  
  <p>Any tips?</p>