class Solution {
boolean isleaf(TreeNode root){
return root.left==null&&root.right==null;
}
public boolean isCompleteTree(TreeNode root) {
if(root==null){
return true;
}
LinkedList<TreeNode> q = new LinkedList<>();
boolean leaf = false;
TreeNode l = null;
TreeNode r = null;
q.add(root);
while(!q.isEmpty()){
root = q.poll();
l = root.left;
r = root.right;
if ((leaf && (l!=null || r!=null)) ||
(l==null && r !=null)){
return false;
}
if(l!=null){
q.add(l);
}
if(r!=null){
q.add(r);
}
if(l==null || r==null){
leaf=true;
}
}
return true;
}
}
class Solution {
public boolean isSubStructure(TreeNode A, TreeNode B) {
if(A ==null || B == null){
return false;
}
return recur(A,B)||isSubStructure(A.left,B)||isSubStructure(A.right,B);
}
public boolean recur(TreeNode A, TreeNode B){
if(B==null) return true;
if(A==null||A.val!=B.val) return false;
return recur(A.left,B.left)&&recur(A.right,B.right);
}
}