#2 RE了,Java写法 不知道错在哪里
查看原帖
#2 RE了,Java写法 不知道错在哪里
405626
OpensourceHU楼主2021/4/8 11:23

    public static void main(String[] args){
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(1, 1);
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int max = 0;
        for (int i = 1; i <= N; i++) {
            int left = scan.nextInt();
            int right = scan.nextInt();
            if(left==0 && right==0)
                continue;
            Integer faH = map.get(i);
            map.put(left, faH + 1);
            map.put(right, faH + 1);
            max = Math.max(max, faH + 1);
        }
        System.out.println(max);
    }

我的思路是 不建树 只统计每个节点和相应高度,输出最大值

2021/4/8 11:23
加载中...