java为啥runtime error啊
查看原帖
java为啥runtime error啊
603097
Brokenrivers楼主2022/3/20 16:31
import java.util.Objects;
import java.util.Scanner;

public class Main {
    static  class node{
        int l,r;
    }
    static node [] tree=new  node[1000];
    static int[] dp=new int [1000];
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        for(int j=1;j<=n;j++){
            tree[j]=new node();
            tree[j].l=in.nextInt();
            tree[j].r=in.nextInt();
        }
        int m=dfs(1);
        System.out.print(dfs(1));
        //return;
    }
    public static int dfs(int idx){
        if(Objects.equals(tree[idx].l, tree[idx].r) &&tree[idx].l==0){
            return 1;
        }
        if (dp[idx] != 0)return dp[idx];
        dp[idx]=Math.max(dfs(tree[idx].l),dfs(tree[idx].r))+1;
        return dp[idx];
    }
}
2022/3/20 16:31
加载中...