Easy 4ms C++ solution

  • 0
    class Solution {
        bool mirror(TreeNode* rt1,TreeNode* rt2){  /*To judge whether two trees are mirrors of each other*/
            if(rt1==NULL) return rt2==NULL;
            if(rt2==NULL) return false;
            if(rt1->val!=rt2->val) return false;
            return mirror(rt1->left,rt2->right)&&mirror(rt1->right,rt2->left);
        bool isSymmetric(TreeNode* root) {
            if(root==NULL) return true;
            return mirror(root->left,root->right);

Log in to reply

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