剑指offer面试题18:二叉树的子结构
2013-01-09 19:55
405 查看
struct BinaryTreeNode { int value; BinaryTreeNode *left,*right; }; bool doestree1havetree2(BinaryTreeNode *root1,BinaryTreeNode *root2); bool hassubtree(BinaryTreeNode *root1,BinaryTreeNode *root2) { bool result=false; if(root1!=NULL&&root2!=NULL) { if(root1->value==root2->value) { result=doestree1havetree2(root1,root2); } if(!result)result=hassubtree(root1->left,root2); if(!result)result=hassubtree(root1->right,root2); } return result; } bool doestree1havetree2(BinaryTreeNode *root1,BinaryTreeNode *root2) { if(root2==NULL) return true; if(root1==NULL) return false; if(root1->value!=root2->value) return false; return doestree1havetree2(root1->left,root2->left)&&doestree1havetree2(root1->right,root2->right); }
相关文章推荐
- 剑指offer面试题18:树的子结构
- 《剑指Offer》面试题18:树的子结构
- 剑指Offer面试题18树的子结构(递归),面试题19二叉树的镜像(递归和非递归用栈)
- 剑指Offer系列-面试题18:树的子结构
- 剑指offer-面试题18 判断二叉树B是不是二叉树A的子结构
- 剑指offer 面试题18: 树的子结构(LintCode 245.Subtree) 题解
- 剑指offer——面试题18:树的子结构
- 剑指Offer---面试题18:树的子结构
- 关于剑指offer的阅读笔记 之面试题18 树的子结构细节错误
- 剑指offer——面试题18:树的子结构
- 剑指offer 18---输入两棵二叉树A和B,判断B是不是A的子结构
- 【剑指offer】面试题18:输入两颗二叉树A和B,判断B是不是A的子结构?
- 【面试题】剑指offer18--判断一个二叉树是否为另一个二叉树的子结构
- 剑指offer之面试题18树的子结构
- (未完成)《剑指offer》(面试题18):树的子结构
- 剑指offer 面试题18 树的子结构
- 剑指Offer:面试题18 树的子结构
- 剑指offer面试题18:树的子结构
- 剑指Offer----面试题18:树的子结构
- 剑指offer-面试题18.树的子结构