题解 | #牛群的轴对称结构#
牛群的轴对称结构
https://www.nowcoder.com/practice/a200535760fb4da3a4568c03c1563689
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param root TreeNode类 * @return bool布尔型 */ #include <stdbool.h> //对比左右节点 bool func(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 func(left->left, right->right) && func(left->right, right->left); } bool isSymmetric(struct TreeNode* root ) { //排除根节点 return func(root->left, root->right); }