1. Problem Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: Java 1 2 3 4 5 1 Java 1 2 3 4 5 1 3 3 2. Idea According to the description, a tree is symmetric if and only if its left subtree and right subtree are mirrored, if and only if They are empty tree; Or their roots have the same value, and one's left subtree and another's right subtree are mirrored, and one's right subtree and another's left subtree are mirrored. As a result, the basic idea is similar to LeetCode - Same Tree ,
Read full article from LeetCode - Symmetric Tree | Darren's Blog
No comments:
Post a Comment