算法和数据结构 相同的树
class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { return dfs(p, q); } bool dfs(TreeNode *pt, TreeNode *qt) { if(pt == NULL && qt == NULL) return true; if(pt == NULL && qt != NULL) return false; if(pt != NULL && qt == NULL) return false; return (pt->val == qt->val) && dfs(pt->left, qt->left) && dfs(pt->right, qt->right); } }; 来源: https://www.cnblogs.com/yangwenhuan/p/12448006.html