public static class Node { public int value; public Node left; public Node right; public Node(int data) { this.value = data; } } public static boolean isFull(Node head){ ReturnData allInfo=process(head, 1); return ((1<<allInfo.level)-1==allINfo.nums; } public static class ReturnData{ public int level; public int nums; public ReturnData(int l, int n){ level=l; nums=n; } } public static ReturnData process(Node head, int level){ if(head==null){ return new ReturnData(level, 0); } ReturnData leftInfo = process(head.left, level+1); ReturnData rightInfo = process(head.right, level+1); int nums = leftInfo.nums + rightInfo.nums+1; int deep = Math.max(leftInfo.level,rightInfo.level); return new ReturnData(deep, nums); } public static class ReturnType { public boolean isBalanced; public int height; public ReturnType(boolean isB, int hei) { isBalanced = isB; height = hei; } }
来源:https://www.cnblogs.com/zyqy/p/11114420.html