my 4ms java solution


  • 0
    A
        public ListNode swapPairs(ListNode head) {
                ListNode x = null;
                if(head == null) return null;
                if(head.next == null) return head;
                x = head.next;
                head.next = x.next;
                x.next = head;
                head.next = swapPairs(head.next);
                return x;
    
        }
    }```

Log in to reply
 

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