var swapPairs = function(head) {
if (head == null || head.next == null) {
return;
}
let oldHead = head;
let nextHead = head.next;
oldHead.next = swapPairs(nextHead.next);
head.next = oldHead;
return head;
};
console.log(swapPairs(list.head));
有什么线索可以解释为什么Node JS会响应每个头部,但响应下一个值时是 "[circular]"?
例如: { value: 16, next: [Circular] }
head.next
设置为head
:head.next = oldHead
。 - Knelis