Пример #1
0
 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);
 }
Пример #2
0
 bool isSymmetric(TreeNode* root) {
     return isMirrorTree(root, root);
 }
Пример #3
0
 bool isSymmetric(TreeNode* root) {
     if (root == nullptr) {
         return true;
     }
     return isMirrorTree(root->left, root->right);
 }
Пример #4
0
 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);
 }