Intuition
This is a straight-forward tree problem. We are provided with two clone trees, and are required to return a corresponding node of type TreeNode
in cloned
.
So, we traverse both the trees at the same pace and then once we find the target
node in original
, we return the cloned
node at that instant.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we would be visiting all nodes in the tree.
-
Memory
The memory usage is since we are not using any extra data structure.
— A