#include <iostream> using namespace std; // 定义链表节点结构体 struct ListNode { int val; ListNode* next; ListNode(int x) : val(x), next(NULL) {} }; // 合并两个有序链表并去重的函数 ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode* dummy = new ListNode(0); ListNode* current = dummy; while (l1 && l2) { if (l1->val < l2->val) { if (current->val!= l1->val) { current->next = l1; current = current->next; } l1 = l1->next; } else { if (current->val!= l2->val) { current->next = l2; current = current->next; } l2 = l2->next; } } while (l1) { if (current->val!= l1->val) { current->next = l1; current = current->next; } l1 = l1->next; } while (l2) { if (current->val!= l2->val) { current->next = l2; current = current->next; } l2 = l2->next; } return dummy->next; }</iostream>