Determine if Two Trees are Identical | Symmetric Tree(Mirror Image)

I came across these 2 questions and found a similarity in the logic part.

  1. Symmetric Tree:

We need to check symmetry for the same tree or say mirror image.

Here comes the solution for the same.

2. Determine 2 Trees are identical or not.

Here we need to check the symmetry for 2 trees.

Here if you can see both the solutions the difference is just 1 line of code:

for Symmetric:

for Two trees identical

The rest of the code is the same!

Thank you for reading!

Happy Coding!

Software Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store