My cpp solution

  • 0
    class Solution
    bool isMirror(TreeNode* r1,TreeNode* r2)
        if(r1==NULL && r2==NULL)return true;
        if(r1==NULL || r2==NULL)return false;
        if(r1->val!=r2->val)return false;
        if(!isMirror(r1->left,r2->right))return false;
        if(!isMirror(r2->left,r1->right))return false;
        return true;
    bool isSymmetric(TreeNode* root) 
        if(root==NULL)return true;
        return isMirror(root->left,root->right);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.