newOldPairs
to map original nodes to their copies.deepCopy(root)
that creates a copy of the tree without random pointers:
root
is NULL
, return NULL
.newRoot
with the same value as root
.deepCopy
for root->left
and root->right
and attach them to newRoot
.root
, newRoot
) in newOldPairs
.newRoot
.mapRandomPointers(oldNode)
to set the random pointers in the copied tree:
oldNode
is NULL
, return.newRootRandom
for newRoot
using newOldPairs
and set the random pointer.mapRandomPointers
for oldNode->left
and oldNode->right
.deepCopy(root)
to create the deep copy of the tree.mapRandomPointers(root)
to set all random pointers.