Question d’entretien chez Meta

Design a binary tree class and write a function to get a deepcopy of the tree

Réponse à la question d'entretien

Utilisateur anonyme

30 oct. 2016

TreeNode* deepCopy(TreeNode* root) { if (! root) return NULL; TreeNode* leftChild = deepCopy(root->left); TreeNode* rightChild = deepCopy(root->right); TreeNode* current = new TreeNode(root->val); current->left = leftChild; current->right = rightChild; return current; }