class Solution { public: ListNode* swapPairs(ListNode* head) { if(head == nullptr || head->next == nullptr) { return head; } ListNode* pre = new ListNode(0, head); ListNode *a = head, *b = head->next, *c = pre; while(b) { … b = temp->next; } return pre->next; } };
|