Simple C++ 4 line solution. easy understanding

  • 0
    bool isSymmetric(TreeNode* root) {
        if (!root) return true;
        return dfs_sym(root->left, root->right);
    bool dfs_sym(TreeNode *left, TreeNode *right) {
        if (!left || !right) return left == right;
        return left->val == right->val && dfs_sym(left->left, right->right) && dfs_sym(left->right, right->left);

Log in to reply

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