public NodeCopy(int val = 0, NodeCopy left = null, NodeCopy right = null, NodeCopy random = null) { this.val = val; this.left = left; this.right = right; this.random = random; }
private NodeCopy CopyRandomBinaryTree(Node node, Dictionary <Node, NodeCopy> map) { if (node == null) { return(null); } if (map.ContainsKey(node)) { return(map[node]); } var newNode = new NodeCopy(node.val); map.Add(node, newNode); newNode.left = CopyRandomBinaryTree(node.left, map); newNode.right = CopyRandomBinaryTree(node.right, map); newNode.random = CopyRandomBinaryTree(node.random, map); return(newNode); }