Symmetric Tree | Javascript Solution
Symmetric Tree is an example of tree problems. In this post we will see how we can solve in Javascript.
Problem Description
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
1 / \ 2 2 / \ / \ 3 4 4 3
But the following [1,2,2,null,3,null,3] is not:
1 / \ 2 2 \ \ 3 3
Note: Bonus points if you could solve it both recursively and iteratively.
Please check the main.js snippet for the solution.
If you have different approach in mind or have any suggestion for this implementation feel free to share in the comment below. Thanks!
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login .