[leetcode] Same Tree

来源:互联网 发布:日本人的素质 知乎 编辑:程序博客网 时间:2024/06/07 17:08

Same Tree

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


0 0
原创粉丝点击