0101. Symmetric Tree
Easy | Tree | 24 ms (99.01%), 14.2 MB (93.95%)
Source: LeetCode - Symmetric Tree GitHub: Solution / Performance
Given the root
of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
While this problem is easy and straightforward, we should be careful with the boundary conditions for both recursive and iterative methods.
Iterative
If both nodes are null, move to the next loop without pushing any nodes onto the stack. If one of the nodes is null, return False. If two nodes' values are different, return False.
Recursive
If both nodes are null, return True. If one of the nodes is null, return False.
Last updated