标签:== logs subject describe code desc bsp int treenode
题目描述:
/* 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; } bool left,right; left = helper(pRoot1 -> left,pRoot2 -> left); right = helper(pRoot1 -> right,pRoot2 -> right); return left && right; } bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2) { if(pRoot1 == nullptr || pRoot2 == nullptr){ return false; } return helper(pRoot1,pRoot2) || helper(pRoot1 -> left,pRoot2) || helper(pRoot1 -> right,pRoot2); } };
标签:== logs subject describe code desc bsp int treenode
原文地址:http://www.cnblogs.com/dingxiaoqiang/p/7467907.html