LeetCode题解之 Subtree of Another Tree
作者:互联网
1、题目描述
2、问题分析
判断一个节点,然后判断子树。
3、代码
1 bool isSubtree(TreeNode* s, TreeNode* t) { 2 if (s == NULL) 3 return false; 4 else { 5 return isSame(s,t) || isSubtree(s->left, t) || isSubtree(s->right, t); 6 } 7 8 } 9 10 bool isSame(TreeNode *t1, TreeNode *t2) 11 { 12 if (t1 == NULL && t2 == NULL) return true; 13 if (t1 == NULL || t2 == NULL) return false; 14 15 return (t1->val == t2->val) && isSame(t1->left, t2->left) && isSame(t1->right , t2->right); 16 } 17
标签:return,题解,t2,t1,Tree,TreeNode,NULL,LeetCode,isSame 来源: https://www.cnblogs.com/wangxiaoyong/p/10459752.html