3 ms·
The "invert binary tree" interview question can be solved by swapping the accessors of the node type: tmpfn = tree.left tree.left = tree.right tree.right
by kazinator 1y ago
The "invert binary tree" interview question can be solved by swapping the accessors of the node type:
tmpfn = tree.left
tree.left = tree.right
tree.right = tmpfn
Now when tree.left(node) is applied, it returns the right child, and vice versa. All traversals use the accessors, QED.