101 Symmetric Tree
题意:
判断一颗二叉树是否对称
代码:
bool comp(TreeNode* l, TreeNode* r) {
if (l == NULL&&r == NULL)
return true;
if (l == NULL||r == NULL)
return false;
if (l->val != r->val)
return false;
return comp(l->left, r->right) && comp(l->right, r->left);
}
bool isSymmetric(TreeNode* root) {
if (!root)
return true;
return comp(root->left, root->right);
}