My 16ms C++ solution


  • 9
    S
    bool DFS(TreeNode *left,TreeNode *right)
    {
        if(left == NULL || right == NULL)
            return left == right;
        return (left->val == right->val)&DFS(left->right,right->left)&DFS(left->left,right->right);
    }
    bool isSymmetric(TreeNode *root) {
        if(root == NULL)
            return true;
        return DFS(root->left,root->right);
    }

Log in to reply
 

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