for (int i = 0; i <= max+1; i++) { list.add(i,0); } int c=0; for (Interval l : airplanes) { int start = l.start; int end = l.end; c++; System.out.println("第"+c+"次遍历开始"); System.out.println("init data in ("+start+" , "+end+")"); for (int i = start; i < end; i++) { list.add(i, list.get(i)+1); System.out.println("end ("+i+" <=> "+list.get(i)+")"); } } return Collections.max(list);Interval的构造器 是public Interval(int start, int end) { this.start = start; this.end = end; }为什么,index为5(6也有这样的问题)的list在第三次遍历的时候被初始化为2,在第4次遍历的时候,不应该被增加到3的麽?
3 回答

慕容森
TA贡献1853条经验 获得超18个赞
Class AbstractList<E>
中 add 方法的文档:
public void add(int index,E element)
Inserts the specified element at the specified position in this list. Shifts the element currently at
that position (if any) and any subsequent elements to the right (adds one to their indices).
添加回答
举报
0/150
提交
取消