We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
出处 LeetCode 算法第138题 给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。 要求返回这个链表的深度拷贝。
出处 LeetCode 算法第138题
给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。
要求返回这个链表的深度拷贝。
用一个map来保存已访问过的节点
/** * @param {RandomListNode} head * @return {RandomListNode} */ function copyRandomList(head) { return copy(head, {}); } function copy(node, map) { if (!node) return node; if (map[node.label]) return map[node.label]; let n = new RandomListNode(node.label); map[node.label] = n; n.next = copy(node.next, map); n.random = copy(node.random, map); return n; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
习题
思路
用一个map来保存已访问过的节点
解答
The text was updated successfully, but these errors were encountered: