标签:bool 节点 div roo style nod amp esc 判断
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: bool helper(TreeNode* pRoot1, TreeNode* pRoot2){ if(pRoot2 == nullptr){ return true; } if(pRoot1 == nullptr){ return false; } if(pRoot1 -> val != pRoot2 -> val){ return false; } return helper(pRoot1 -> left,pRoot2 -> left) && helper(pRoot1 -> right,pRoot2 -> right); } bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2){ if(pRoot1 == nullptr || pRoot2 == nullptr){ return false; } bool result = false; if(pRoot1 -> val == pRoot2 -> val){ result = helper(pRoot1,pRoot2); } if(!result){ result = helper(pRoot1 -> left,pRoot2); } if(!result){ result = helper(pRoot1 -> right,pRoot2); } return result; } };
标签:bool 节点 div roo style nod amp esc 判断
原文地址:http://www.cnblogs.com/dingxiaoqiang/p/7932038.html