3217.cpp (422B)
1 class Solution { 2 public: 3 ListNode *modifiedList(const vector<int> &nums, ListNode *head) const { 4 const unordered_set<int> us(begin(nums), end(nums)); 5 ListNode dummy(-1, head); 6 7 for (auto *p = &dummy; p && p->next;) { 8 if (!us.count(p->next->val)) 9 p = p->next; 10 else 11 p->next = p->next->next; 12 } 13 14 return dummy.next; 15 } 16 };