标签:
class Solution { public: bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2) { bool result= false; if(pRoot1!=NULL&&pRoot2!=NULL){ if(pRoot2->val == pRoot2->val) result=equal(pRoot1,pRoot2); if(!result) result=equal(pRoot1->left,pRoot2); if(!result) result=equal(pRoot1->right,pRoot2); } return result; } bool equal(TreeNode* pa,TreeNode* pb) { if(pb==NULL) return true; if(pa==NULL) return false; if(pa->val!=pb->val) return false; return equal(pa->left,pb->left)&&equal(pa->right,pb->right); } };
标签:
原文地址:http://www.cnblogs.com/daocaorenblog/p/5348473.html