Answer the question
In order to leave comments, you need to log in
How to implement invert function for binary tree?
Hey!
It is necessary to implement the invert function for a binary tree.
Example:
Input (schematic)
:
4
/ \
2 7
/ \ / \
1 3 6 9
:
4
/ \
7 2
/ \ / \
9 6 3 1
const tree = {left: {value: 2}, value: 1, right:{value: 4}}
const inverted = invertTree(tree);
{left: {value: 4}, value: 1, right:{value: 2}}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question