为什么我的算法显示 [循环]? (NodeJS简单算法)
Why does my algorithm say [circular]? (NodeJS simple algorithm)
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]”吗?
例如:
{值:16,下一个:[循环]}
因为它是圆形的 - 它是无限嵌套的:
value: 16,
next: {
next: {
next: {...}
}
}
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]”吗?
例如: {值:16,下一个:[循环]}
因为它是圆形的 - 它是无限嵌套的:
value: 16,
next: {
next: {
next: {...}
}
}