119. Pascal's Triangle II#1(Done)

来源:互联网 发布:淘宝助理起到什么作用 编辑:程序博客网 时间:2024/05/22 00:02

Solution

public class Solution {    public List<Integer> getRow(int rowIndex) {        if (rowIndex < 0) {            throw new IllegalArgumentException("Argument for getRow is illegal");        }        List<Integer> result = new ArrayList<Integer>(rowIndex + 1);        for (int i = 0; i < rowIndex + 1; i++) {            result.add(1);        }        for (int i = 2; i < rowIndex + 1; i++) {             int last = 1;             for (int j = 1; j < i / 2 + 1; j++) {                 int tmp = last;                 last = result.get(j);                 result.set(j, tmp + last);                 result.set(i - j, tmp + last);             }        }        return result;    }}

Problem#1

0 0