判断是否是满二叉树

北战南征 提交于 2020-01-30 15:42:05
    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;
        }
    }

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!