leetcode:572.另一棵树的子树

leetcode:572.另一棵树的子树_第1张图片

bool isSubtree(struct TreeNode* root, struct TreeNode* subRoot) {
    if(root == NULL && subRoot == NULL)
        return true;
    if (root == NULL)
        return false;
    if (subRoot == NULL)
        return true;
    if(isSameTree(root,subRoot))
        return true;
    if (root->left != NULL && isSameTree(root->left,subRoot))
        return true;
    if (root->right != NULL && isSameTree(root->right,subRoot))
        return true;
    return isSubtree(root->left,subRoot) || isSubtree(root->right,subRoot);
}

你可能感兴趣的:(数据结构,leetcode,linux,算法)