满二叉树
嗯,递归套路的代码很清晰。
public class isMST {
public static boolean Inof(Node head){
if (head==null) {
return true;
}
In data = process(head);
// return data.nodes == Math.pow(2,data.height)-1;
return data.nodes == (1<<data.height-1);
}
public static class In{
public int height;
public int nodes;
public In(int he,int n){
height = he;
nodes = n;
}
}
public static In process(Node x ){
if (x==null){
return new In(0,0);
}
In leftData = process(x.left);
In rightData = process(x.right);
int height = Math.max(leftData.height,rightData.height)+1;
int nodes = leftData.nodes+rightData.nodes+1;
return new In(height,nodes);
}
}
最近学的很慢 ! 加快进度