bool isMirrorTree(TreeNode* p, TreeNode* q) { if (p == NULL && q == NULL) { return true; } if (p == NULL || q == NULL) { return false; } return p->val == q->val && isMirrorTree(p->left, q->right) && isMirrorTree(p->right, q->left); }
bool isSymmetric(TreeNode* root) { return isMirrorTree(root, root); }
bool isSymmetric(TreeNode* root) { if (root == nullptr) { return true; } return isMirrorTree(root->left, root->right); }
bool isMirrorTree(TreeNode* p, TreeNode* q) { if ((p == nullptr) || (q == nullptr)) { return p == q; } return (p->val == q->val) && isMirrorTree(p->left, q->right) && isMirrorTree(p->right, q->left); }