How to understand constant space?


  • 0
    R
    public class Solution {
    public ListNode swapPairs(ListNode head) {
        ListNode swap;
        ListNode nextSwap;
        
        if(head == null || head.next == null)
            return head;
    
        swap = head;
        head = head.next;
        nextSwap = head.next;
        head.next = swap;
        swap.next = swapPairs(nextSwap);
        return head;
    }
    

    }

    i use the recursion solusion, does it satisfied the constant space? though it is accepted.


Log in to reply
 

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