0024-Medium-两两交换链表中的节点
最后更新于
最后更新于
输入:head = [1,2,3,4]
输出:[2,1,4,3]输入:head = []
输出:[]输入:head = [1]
输出:[1]class Solution {
public ListNode swapPairs(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode next = head.next;
head.next = swapPairs(next.next);
next.next = head;
return next;
}
}