struct ListNode* reverseKGroup(struct ListNode* head, int k ) { struct ListNode dummy; dummy.next = head; struct ListNode* pre = head; int cnt1 = 0; while(pre){ ++cnt1; pre = pre->next; } int cnt = cnt1/k; struct ListNode* pre1=&dummy; struct ListNode* cur = pre1->next;...
{ int data; struct ListNode *next; }; struct ListNode* mergelists(struct ListNode* list1, struct ListNode* list2) { // 创建一个哑节点作为新链表的头节点,方便后续操作 struct ListNode dummy; dummy.next = NULL; struct ListNode* tail = &dummy; // 遍历两个链表,合并到新的链表中 while ...
priority_queue<ListNode*, vector<ListNode*>, cmp> q; ListNode* p = head; while (p) { q.push(p); p = p->next; } ListNode dummy(0); p = &dummy; while (q.size() > 0) { p->next = q.top(); q.pop(); p = p->next; } p->next = nullptr; return dummy.next; } ...