美文网首页
100.same-tree

100.same-tree

作者: Optimization | 来源:发表于2020-05-21 20:54 被阅读0次

又简单复杂!!!

class Solution {
public:
    bool isSameTree(TreeNode* p, TreeNode* q) {
        // 递归终止条件
        if(!p && !q) return true;
        if(!p ||!q) return false;

        // 判断过程
        if(p->val == q->val){
            // 不能加
            //return true;
        } else {
            return false;
        }
        return (isSameTree(p->left,q->left)&&isSameTree(p->right,q->right));
    }
};

相关文章

网友评论

      本文标题:100.same-tree

      本文链接:https://www.haomeiwen.com/subject/fbxxahtx.html