Leetcode 101-symmetric Tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.