101. 对称二叉树(C语言)

bool Symmetric(struct TreeNode* lroot,struct TreeNode*rroot){
    if(lroot==NULL&&rroot==NULL)return true;
    if(lroot==NULL||rroot==NULL)return false;
  
    return (lroot->val==rroot->val)&&Symmetric(lroot->left,rroot->right)&&Symmetric(lroot->right,rroot->left);
    
}

bool isSymmetric(struct TreeNode* root){
     return Symmetric(root,root);//同时传两个根节点
}

转自:https://leetcode-cn.com/problems/symmetric-tree/solution/cyu-yan-jian-jian-dan-dan-ji-xing-dai-ma-jie-jue-4/

你可能感兴趣的:(力扣题目)