// Start typing your Java solution below
// DO NOT write main() function
if(root == null || root.left==null && root.right==null) return true;
if(root.left!=null && root.right!=null){
if(root.left.val == root.right.val){
return checkTree(root.left.right, root.right.left) &&
checkTree(root.left.left, root.right.right);
}
}
return false;
}
boolean checkTree(TreeNode first, TreeNode second){
if(first==null && second ==null) return true;
if(first==null || second == null) return false;
if(first.val !=second.val) return false;
return checkTree(first.left, second.right) &&
checkTree(first.right, second.left);
}
没有评论:
发表评论