Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
1 / \ 2 2 / \ / \ 3 4 4 3
But the following is not:
1 / \ 2 2 \ \ 3 3
Use recursion. Be clear about the ending recursion conditions.
- One of left and right child tree is null?
- Both child trees are null?
How to pass on the nodes for detection? Use recursion to think about it for you! Just generalize the simplest condition for the root node and apply this as the recursion return statement.