Dart solution (using hash map, and with printout)
Some care might be required to handle null nexts.\nOne can also sort the nums and perform binary search to save on space, but that will cause the performance to
Some care might be required to handle null nexts.\nOne can also sort the nums and perform binary search to save on space, but that will cause the performance to go linearithmic.\n\n```\n/**\n * Definition for singly-linked list.\n * class ListNode {\n *   int val;\n *   ListNode? next;\n *   ListNode([this.val = 0, this.next]);\n * }\n */\nclass Solution {\n  ListNode? modifiedList(List<int> nums, ListNode? head) {\n    Set<int> numset = {};\n    for (int k in nums) {\n      numset.add(k);\n    }\n    while(head != null && numset.contains(head.val)) {\n      head = head.next;\n    }\n    ListNode? cur = head;\n    ListNode? next = head?.next;\n    while (next != null) {\n      print("${cur?.val} ${next.val}");\n      while (next != null && numset.contains(next.val)) {\n        next = next.next;\n      }\n      cur?.next = next;\n      cur = cur?.next;\n      next = next?.next;\n    }\n\n    return head;\n  }\n}\n```
[]