美文网首页
symmetric-tree

symmetric-tree

作者: DaiMorph | 来源:发表于2019-05-04 10:18 被阅读0次
class Solution {
public:
    bool isSymmetric(TreeNode *root) {
        if(!root)return true;
        return judge(root,root);
    }
    bool judge(TreeNode*r1,TreeNode*r2)
    {
        if(!r1&&!r2)return true;
        if(!r1||!r2)return false;
        if(r1->val!=r2->val)return false;
        return judge(r1->left,r2->right)&&judge(r1->right,r2->left);
    }
};

相关文章

网友评论

      本文标题:symmetric-tree

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