zhedahht / CodingInterviewChinese2

《剑指Offer:名企面试官精讲典型编程面试题》第二版源代码
Other
5.32k stars 2.17k forks source link

面试题26:逻辑不全,对于部分测试用例无法AC,对应LintCode 245 #42

Open FantasyJXF opened 5 years ago

FantasyJXF commented 5 years ago
    bool hasSubtree(TreeNode *T1, TreeNode *T2)
    {
        if(T2==nullptr && T1==nullptr)
            return true;

        if (T1 != nullptr && T2!=nullptr && T1->val == T2->val)
        {
                return hasSubtree(T1->left,T2->left) && hasSubtree(T1->right,T2->right);
        }
        return false;
    }