【问题标题】:Why does my algorithm say [circular]? (NodeJS simple algorithm)为什么我的算法说[循环]? (NodeJS 简单算法)
【发布时间】:2019-04-04 06:19:24
【问题描述】:
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 会响应每个 head 但会响应下一个值“[循环]”?

例如: { 值:16,下一个:[循环] }

【问题讨论】:

标签: javascript node.js algorithm object circular-dependency


【解决方案1】:

因为它是圆形的——它是无限嵌套的:

value: 16,
next: {
    next: {
        next: {...}
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-09
    • 2021-03-16
    • 1970-01-01
    相关资源
    最近更新 更多