6ms short C++ recursive code

  • 0
        bool isSymmetric(TreeNode* root) {
            return !root or _isSymmetric(root->left, root->right);
        bool _isSymmetric(TreeNode* left, TreeNode* right) {
            if (!left or !right) return left == right;
            else if (left->val != right->val) return false;
            else return _isSymmetric(left->left, right->right) and _isSymmetric(left->right, right->left);

Log in to reply

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