问题:定义一个链表结构如下:
    struct ListNode {
    int value;
    struct ListNode *next;
    };
    请写一个程序,实现链表中重复节点的删除(同一值的节点只保留一个),且链表顺序保持不变。如,
    初始链表:3 -> 2 -> 3 -> 4 -> 4 -> 1 -> 7 -> 8
    节点去重后的链表:3 -> 2 -> 4 -> 1 -> 7 -> 8
    注意:初始链表是非排序链表

    1. ListNode* head = new ListNode(1);
    2. /*ListNode* p = head;
    3. for(int i = 2; i <= 5; ++ i){
    4. p->next = new ListNode(i);
    5. p = p->next;
    6. p->next = new ListNode(i);
    7. p = p->next;
    8. }*/
    9. cout<<endl;
    10. unordered_set<int> mset;
    11. ListNode* nhead = head;
    12. ListNode* pre = nullptr;
    13. while(nhead){
    14. int x = nhead->val;
    15. if(!mset.count(x)){
    16. mset.insert(x);
    17. }else{
    18. pre->next = nhead->next;
    19. }
    20. pre = nhead;
    21. nhead = nhead->next;
    22. }/*
    23. while(head){
    24. cout<< head->val << " ";
    25. head = head->next;
    26. }*/
    27. return 0;
    28. }