class Node{
Integer data;
Node left;
Node right;
public Node(int data) {
this.data = data;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Node node = (Node) o;
return Objects.equals(data, node.data);
}
@Override
public int hashCode() {
return Objects.hash(data);
}
}
private static boolean isFullTree(Node root) {
Queue<Node> qu = new LinkedList<>();
qu.add(root);
int m = 0, height = 0, n = 1, t = 1;
while(!qu.isEmpty()){
Node node = qu.poll();
n--;
if(node.left != null){
qu.add(node.left);
m++;
}
if(node.right != null){
qu.add(node.right);
m++;
}
if(n == 0){
n = m;
t += n;
m = 0;
height++;
}
}
return t == ((1 << height) - 1);
}