Accepted 4ms solution using recursion

  • 0
    class Solution 
        bool equal(TreeNode* left, TreeNode* right)
            if (!left && !right) return true;
            if (left && right)
                if (left->val != right->val) return false;
                else return equal(left->left, right->right) && equal(left->right, right->left);
            else return false;
        bool isSymmetric(TreeNode* root) {
            if (!root) return true;
            else return equal(root->left, root->right);

Log in to reply

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