Recursive C solution. (Why so few C solutions?)

  • 0
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     struct TreeNode *left;
     *     struct TreeNode *right;
     * };
    bool isMirror(struct TreeNode *p, struct TreeNode *q)
        if (!p && !q) return true;
        else if (!p || !q) return false;
        else if (p->val != q->val) return false;
            return isMirror(p->left, q->right) && isMirror(p->right, q->left);
    bool isSymmetric(struct TreeNode* root) {
        if (!root) return true;
        return isMirror(root->left, root->right);

  • 0
    This post is deleted!

Log in to reply

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