My 4ms recursive C++ solution


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

Log in to reply
 

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