3ms C++, 100% beats solution


  • 3
    E

    class Solution {
    public:
    bool isSymmetric(TreeNode* root) {
    return isMirror(root,root);
    }
    private:
    bool isMirror(TreeNode *root1,TreeNode *root2)
    {
    if(!root1 && !root2) return true;
    if(root1 && root2 && root1->val==root2->val)
    return isMirror(root1->left,root2->right) && isMirror(root1->right,root2->left);
    return false;
    }
    };


Log in to reply
 

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