My simple recursive Java solution

  • 0
    public ListNode swapPairs(ListNode head) {
        if (head == null || == null) return head;
        else {
            ListNode newHead =;
   = swapPairs(; //recursively call swapPairs function to reverse two paired Nodes
   = head;
            return newHead;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.