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: {...}
}
}
关于javascript - 为什么我的算法显示 [循环]? (NodeJS简单算法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55509089/