题解 | #对称的二叉树#
对称的二叉树
https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb
//写树的时候最好用模拟+递归; #include <stdbool.h> bool isMirror(struct TreeNode* left,struct TreeNode* right) { if(left==NULL&&right==NULL) return true; if(left==NULL||right==NULL) return false; if(left->val!=right->val) return false; return isMirror(left->left,right->right)&&isMirror(left->right,right->left); } bool isSymmetrical(struct TreeNode* root ) { if(!root) return true; return isMirror(root->left,root->right); }