Home > Reflections | โฎ๏ธ โญ๏ธ
2024-07-07 | ๐ผ Job ๐ Search | ๐ช Symmetree ๐ฒ
๐ง Education
๐ 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.