如何在2D LinkedList
的底部添加一行O(1)
?我一直在運行循環,但我必須在O(1)中實現它。可以幫忙嗎?在2D鏈接列表末尾添加一條線
[0,0,0,0]
[0,0,0,0]
[0,0,0,0]
[0,0,0,0]
.........//I want to add one more line here <-----
LinkedList<LinkedList<T>> myList = new LinkedList<LinkedList<T>>();
public void addLastLine(){
LinkedList<T> rowLine = new LinkedList<T>();
this.lastRow += 1;
myList.add(lastRow, rowLine);
for(int col = 0; col <= origCol; col++){
rowLine.add(col, this.element);
}
}
你想添加什麼行? –
@DhiwaTdG,我想在O(1) –