Reverse Linked list pair by pair

public ListNode reverse(ListNode head) {

if (head == null || head.next == null) {

        return head;

    }



    ListNode newHead  = head.next;

    ListNode next = reverse(head.next.next);

    head.next.next = head;

    head.next = next;



    return newHead;

}

results matching ""

    No results matching ""