标签:desc div class str 树结构 scribe offer tle treenode
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: bool issubtree(TreeNode* p1, TreeNode* p2){ if(p2 == nullptr) return true; if(p1 == nullptr) return false; if(p1 -> val == p2 -> val){ return issubtree(p1 -> left, p2 -> left) && issubtree(p1 -> right, p2 -> right); }else return false; } bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2) { if(pRoot2 == nullptr || pRoot1 == nullptr) return false; return HasSubtree(pRoot1 -> left, pRoot2) || HasSubtree(pRoot1 -> right, pRoot2) || issubtree(pRoot1, pRoot2); } };
标签:desc div class str 树结构 scribe offer tle treenode
原文地址:https://www.cnblogs.com/BillowJ/p/12722022.html