recursive 5ms java solution


  • 1
    S
    public ListNode swapPairs(ListNode head) {
            if(head == null || head.next == null){
                return head;
            }
            ListNode slow = head;
            ListNode fast = head.next;
            slow.next = fast.next;
            fast.next = slow;
            head = fast;
            slow.next = swapPairs(slow.next);
            return head;
        }
    

Log in to reply
 

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