Swap Nodes in Pairs 2020-09-11 05:13

Problem Description

public static ListNode swapPairs(ListNode head) {
    if (head == null || head.next == null) {
        return head;
    }
    ListNode cursor = head.next;
    head.next = swapPairs(cursor.next);
    cursor.next = head;
    return cursor;
}
Runtime Memory
0 ms 36.9 MB

henryxi leetcode list

EOF