https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/


Runtime: 12 ms, faster than 24.02% of C++ online submissions for Remove Duplicates from Sorted List II.
Memory Usage: 12.1 MB, less than 6.32% of C++ online submissions for Remove Duplicates from Sorted List II.


```c++
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
      //6:55
      if (head == nullptr) {
        return nullptr;
      }

      vector<ListNode*> node_list;
      vector<int> value_list;
      vector<int> duplicates;

      auto node = head;
      while (node != nullptr) {
        node_list.push_back(node);
        if (find(value_list.begin(), value_list.end(), node->val) != value_list.end()) {
          duplicates.push_back(node->val);
        } else {
          value_list.push_back(node->val);
        }
        node = node->next;
      }

      vector<ListNode*> new_node_list;
      for (auto node : node_list) {
        if (find(duplicates.begin(), duplicates.end(), node->val) == duplicates.end()) {
          new_node_list.push_back(node);
        } 
      }

      for (int i=0; i < new_node_list.size(); i++) {
        if (i != new_node_list.size()-1) {
          new_node_list[i]->next = new_node_list[i+1];
        } else {
          new_node_list[i]->next = nullptr;
        }
      }

      if (new_node_list.size() == 0) {
        return nullptr;
      } else {
        return new_node_list[0];
      }
      //7:01
    }
};
```