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的構(gòu)造器 是public Interval(int start, int end) { this.start = start; this.end = end; }為什么,index為5(6也有這樣的問題)的list在第三次遍歷的時候被初始化為2,在第4次遍歷的時候,不應(yīng)該被增加到3的麼?
3 回答

慕容森
TA貢獻(xiàn)1853條經(jīng)驗 獲得超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
提交
取消