class segment implements Comparable<segment> { public int start, end; public int compareTo(segment s) { return this.end - s.end; } public segment() { this.start = 0; this.end = 0; } }
public static void main(String[] args) {
Scanner cin = new Scanner(new BufferedInputStream(System.in));
int n; n = cin.nextInt(); segment[] seg = new segment[n]; boolean[] vis = new boolean[n]; Arrays.fill(vis, false); int[] ans = new int[n]; int cnt = 0;
------解决方案-------------------- 你之实例化了 seg 数组 并没有对数组进行初始化和赋值 所以数组里面都是空对象
------解决方案-------------------- segment[] seg = new segment[n]; //这个是给数组分配空间 seg[i] = new segment(); //这个是给数组元素分配空间,注意二者的区别