Links: https://leetcode.com/problems/symmetric-tree/
This question is to determine whether a binary tree is a symmetric binary tree, just beginning to think that the middle sequence traversal output, and then see if it is a string of words back, but this idea is wrong, such as [1,2,3,#,3,#,2].
The code is as follows:
By judging the left child's Zuozi and right child's right subtree and left child's right sub-tree and right child's Zuozi
Class Solution {public: bool Isjudging (TreeNode *nodeleft, TreeNode *noderight) { if (nodeleft! = NULL && Noderight! = NULL && Nodeleft->val = = noderight->val) { return isjudging (Nodeleft->left, Noderight->right) & Isjudging (Nodeleft->right, noderight->left); } else if (Nodeleft = = NULL && Noderight = = null) return true; else return false; } BOOL Issymmetric (TreeNode *root) { if (root = NULL) return true; Return isjudging (Root->left, root->right); };
Leetcode 101-symmetric Tree