Home > Reflections | ⏮️ ⏭️

2024-07-07

🧠 Education

The 2-Hour Job Search

🏋 Coding Practice

Previously, I solved the LeetCode 101. Symmetric Tree.
On my first attempt, I actually failed to solve the problem, attempting an approach that didn’t work out.
Last time, I did implement a working solution, but it felt like more work than was necessary.
Today, I looked up the official solution, and see that they demonstrate a recursive approach that I hadn’t identified.
I find this approach interesting, because their isMirror function is nearly identical to the equal function I implemented as a helper in my working solution.
I struggled to find a recursive solution that directly solves the problem because I wasn’t able to see how we could keep track of both sides of the tree independently as we recursively descend.
I see that they solved this by creating an isMirror function that takes 2 trees, and descends each one recursively.