VaultBy ENSAMIENParrainage
C12 lines

symmetric-tree.c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// By CHOUBIK Houssam - Time complexity O(n)

bool isSymmetric(struct TreeNode* root) {
    if(root==NULL) return true;
    bool check(struct TreeNode* t1, struct TreeNode* t2) {
        if (t1 == NULL && t2 == NULL) return true;
        if (t1 == NULL || t2 == NULL) return false;
        if (t1->val != t2->val) return false;
        return check(t1->left, t2->right) && check(t1->right, t2->left);
    }
    return check(root->left, root->right);
}

    Type at least 2 letters. ↑ ↓ to move, Enter to open.