Title: #1485 - Clone Binary Tree With Random Pointer - LeetCode JavaScript Solutions
Open Graph Title: #1485 - Clone Binary Tree With Random Pointer - LeetCode JavaScript Solutions
X Title: #1485 - Clone Binary Tree With Random Pointer - LeetCode JavaScript Solutions
Description: A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a...
Open Graph Description: A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a...
X Description: A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/clone-binary-tree-with-random-pointer
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/clone-binary-tree-with-random-pointer","name":"#1485 - Clone Binary Tree With Random Pointer - LeetCode JavaScript Solutions","description":"A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * // Definition for a _Node.\n * function _Node(val, left, right, random) {\n * this.val = val === undefined ? null : val;\n * this.left = left === undefined ? null : left;\n * this.right = right === undefined ? null : right;\n * this.random = random === undefined ? null : random;\n * };\n */\n\n/**\n * @param {_Node} root\n * @return {NodeCopy}\n */\nvar copyRandomBinaryTree = function(root) {\n if (!root) return null;\n const nodeMap = new Map();\n return createCopy(root);\n\n function createCopy(node) {\n if (!node) return null;\n if (nodeMap.has(node)) return nodeMap.get(node);\n\n const copy = new NodeCopy(node.val);\n nodeMap.set(node, copy);\n\n copy.left = createCopy(node.left);\n copy.right = createCopy(node.right);\n copy.random = createCopy(node.random);\n\n return copy;\n }\n};","keywords":"LeetCode 1485, #1485 - Clone Binary Tree With Random Pointer, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/clone-binary-tree-with-random-pointer |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/clone-binary-tree-with-random-pointer/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/1485-clone-binary-tree-with-random-pointer.js |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Depth-First Search | https://leetcodejavascript.com/tags/depth-first-search |
| Tree | https://leetcodejavascript.com/tags/tree |
| Breadth-First Search | https://leetcodejavascript.com/tags/breadth-first-search |
| Binary Tree | https://leetcodejavascript.com/tags/binary-tree |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow