How to understand constant space?

  • 0
    public class Solution {
    public ListNode swapPairs(ListNode head) {
        ListNode swap;
        ListNode nextSwap;
        if(head == null || == null)
            return head;
        swap = head;
        head =;
        nextSwap =; = swap; = 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.