Open Shawngbk opened 8 years ago
执行过程 i=0, list 1 i=1, list 11 i=2, list 111, j=1 set(j, 1+1), list 121 i=3, list 1121, j=1 set(j, 2+1) list 1321 j=2 set(j,2+1) list 1331
public class Solution { public List getRow(int rowIndex) { List list = new ArrayList<>(); if(rowIndex < 0) return list; for(int i = 0; i < rowIndex + 1; i++) { list.add(0, 1); for(int j = 1; j < list.size() - 1; j++) { list.set(j, list.get(j) + list.get(j + 1)); } } return list; } }
执行过程 i=0, list 1 i=1, list 11 i=2, list 111, j=1 set(j, 1+1), list 121 i=3, list 1121, j=1 set(j, 2+1) list 1321 j=2 set(j,2+1) list 1331
public class Solution { public List getRow(int rowIndex) {
List list = new ArrayList<>();
if(rowIndex < 0)
return list;
for(int i = 0; i < rowIndex + 1; i++) {
list.add(0, 1);
for(int j = 1; j < list.size() - 1; j++) {
list.set(j, list.get(j) + list.get(j + 1));
}
}
return list;
}
}