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]}
因为它是圆形的 - 它是无限嵌套的:
value: 16,
next: {
next: {
next: {...}
}
}