LeetCode——Pascal's Triangle II

Description:

Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3, Return [1,3,3,1].

public class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<List<Integer>> list = new ArrayList<List<Integer>>();
        for(int i=0; i<=rowIndex; i++) {
            List<Integer> tList = new ArrayList<Integer>();
            if(i == 0) {
                tList.add(1);
            }
            else {
                for(int j=0; j<=i; j++) {
                    if(j == 0 || j == i) {
                    tList.add(1);
                }
                else {
                    tList.add(list.get(i-1).get(j) + list.get(i-1).get(j-1));
                }
                }
            }
            list.add(tList);
        }
        return list.get(rowIndex);
        
    }
}
原文地址:https://www.cnblogs.com/wxisme/p/4589816.html