首页 > 代码库 > Same Tree

Same Tree

问题:判断两棵二叉树是否相等

class Solution {public:    bool isSameTree(TreeNode *p, TreeNode *q) {        if(!( (p && q && p->val==q->val) || (p==NULL && q==NULL))) return false;        if(p==NULL || q==NULL) return true;        return isSameTree(p->left,q->left) && isSameTree(p->right,q->right);    }};