给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。
给定1->2->3->4
, 你应该返回2->1->4->3
class Solution {
public ListNode swapPairs(ListNode* head) {
if(!head || !head->next) return head;
ListNode* first = head;
ListNode* second = head->next;
head = second;
first->next = swapPair(second->next);
second->next = first;
return head;
}
}