Analysis: First determine if the tree is empty and whether it is just a root node. If satisfied, it is a symmetric tree. The left and right subtrees are not empty at the same time.
If this is not the case, recursively traverse each node of the tree (left child of each node in the left subtree = right child of each node in the same layer right subtree && the right child of each node in the left dial hand tree = left child of each node in the right subtree of the same layer)
/* public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
Public TreeNode (int val) {
This.val = val;
}
}
*/
public class Solution {
Boolean issymmetrical (TreeNode proot) {
if (Proot = = NULL | | proot.left = = NULL && proot.right ==null) {
return true;
}
return symmetrical (proot.left,proot.right);
}
Boolean symmetrical (TreeNode Left,treenode right) {
if (left ==null && right = = null) {
return true;
}
if (Left ==null | | right ==null) {
return false;
}
if (Left.val = = Right.val) {
return symmetrical (left.left,right.right) && symmetrical (left.right,right.left);
}
return false;
}
}