Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 807 Bytes

File metadata and controls

37 lines (28 loc) · 807 Bytes

### 解题思路

Quite easy after solving 118.

### 代码

class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<List<Integer>> triangle = generate(rowIndex+1);
        return triangle.get(rowIndex);

    }
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> triangle = new ArrayList<>();

        for (int i=0; i< numRows; i++){
            List<Integer> row = new ArrayList<>();
            row.add(1);
            if (i >= 2){
                for (int j = 1; j<i; j++){
                    row.add(triangle.get(i-1).get(j-1) + triangle.get(i-1).get(j));
                }
            }
            if (i >= 1){
                row.add(1);
            }
            triangle.add(row);
        }
        return triangle;

    }
}