LeetCode 101-invalid Ric Tree, leetcodesametree

Source: Internet
Author: User

LeetCode 101-invalid Ric Tree, leetcodesametree

Link: https://leetcode.com/problems/symmetric-tree/

This is to determine whether a binary tree is a symmetric binary tree. At the beginning, I thought that the output would be a forward traversal and then I checked whether it was a return string. But this idea is wrong, for example, [1, 2, 3 ,#, 3, #, 2].

The Code is as follows:

Determine the left subtree of the Left Child and the right subtree of the right child, and the right subtree of the left child and the Right child

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 isequalric (TreeNode * root) {if (root = NULL) return true; return isJudging (root-> left, root-> right );}};


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.