题解 | #对称的二叉树#

对称的二叉树

https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb

/*
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution {
    boolean isSymmetrical(TreeNode pRoot) {
        return judge(pRoot,pRoot);
    }

    boolean judge(TreeNode p, TreeNode q){
        if(p==null&&q==null){
            return true;
        }else if(p==null || q==null){
            return false;
        }
        return p.val==q.val && judge(p.left,q.right) && judge(q.left,p.right);
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务