1. // 信息结构
    2. public static class Info{
    3. public int nodes;
    4. public int height;
    5. public Info(int nodes, int height) {
    6. this.nodes = nodes;
    7. this.height = height;
    8. }
    9. }
    10. // 判断
    11. public static Boolean isFullMain(Node head){
    12. if(head == null){
    13. return null;
    14. }
    15. Info info = isFull(head);
    16. return Math.pow(2, info.height)-1 == info.nodes;
    17. }
    18. public static Info isFull(Node head){
    19. if(head == null){
    20. return new Info(0, 0);
    21. }
    22. // 左树要信息 右树要信息
    23. Info leftReturn = isFull(head.left);
    24. Info rightReturn = isFull(head.right);
    25. // 自己也要弄信息
    26. int nodes = 0;
    27. int height = 0;
    28. // 自己也算一个 一层
    29. nodes = leftReturn.nodes + rightReturn.nodes + 1;
    30. height = Math.max(leftReturn.height , rightReturn.height)+1;
    31. return new Info(nodes,height);
    32. }