4 lines of c++ solution /3ms


  • 0
    W

    '''
    class Solution {
    public:
    bool isSymmetric(TreeNode* root) {
    if(root==NULL) return true;
    return isSymmetric(root->left, root->right);
    }
    bool isSymmetric(TreeNode* root1,TreeNode* root2){
    if(root1==NULL || root2==NULL) return root1==root2;
    return (root1->val==root2->val)&&isSymmetric(root1->left,root2->right)&&isSymmetric(root1->right,root2->left);
    }
    };
    '''


Log in to reply
 

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