Pascal's triangle: Difference between revisions

(→‎Summing from Previous Rows: initial "last" is never used)
Line 341:
if(rows < 0) return;
//save the last row here
LinkedList<Integer> last = nullnew LinkedList<Integer>();
for(int i= 0;i <= rows;++i){
//work on the next row
LinkedList<Integer> thisRow= new LinkedList<Integer>();
for(int j= 0;j <= i;++j){//loop the number of elements in this row
if(j == last.size() || j == 0){//if we're on the ends
thisRow.add(1);
Line 352:
}
}
thisRow.add(1);
last= thisRow;//save this row
System.out.println(thisRow);
Anonymous user