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; }
public void DFS(Node node, NodeCopy copy) { if (node == null) { return; } copy.random = node.random == null ? null : dict[node.random]; DFS(node.left, copy.left); DFS(node.right, copy.right); }
public NodeCopy CopyNode(Node node) { if (node == null) { return(null); } var copy = new NodeCopy(node.val); dict[node] = copy; copy.left = CopyNode(node.left); copy.right = CopyNode(node.right); return(copy); }