Recursive C++ Solution


  • 1
    M
    bool checkSymm(TreeNode *left, TreeNode *right){
            if(left == NULL && right == NULL) return true;
            else if(left == NULL || right == NULL) return false;
            else if(left->val != right->val) return false;
            return checkSymm(left->left, right->right) && checkSymm(left->right, right->left);
    }
    bool isSymmetric(TreeNode* root) {
            if(root == NULL) return true;
            return checkSymm(root->left, root->right);
    }

  • 0
    This post is deleted!

  • 0
    M
    This post is deleted!

Log in to reply
 

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