100-判断两颗树是否相同
作者:互联网
递归判断
class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) {
if(p==null&&q==null){
return true;
}
if(p==null||q==null){
return false;
}
//不能写q.val==p.val;
if(p.val != q.val){
return false;
}
return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
}
}
标签:right,return,相同,val,TreeNode,isSameTree,两颗,100,null 来源: https://blog.csdn.net/qch60925/article/details/113834316