[leetcode 119]Pascal's Triangle II

来源:互联网 发布:ug软件全称 编辑:程序博客网 时间:2024/04/28 06:28
public class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> rl=new ArrayList<Integer>();
        int[] triArray=new int[rowIndex+1];
        for(int i=0;i<rowIndex+1;++i){
            for(int j=i;j>=0;--j){
                if(j==i){
                    triArray[i]=1;
                }else if(j==0){
                    triArray[0]=1;
                }else{
                    triArray[j]=triArray[j]+triArray[j-1];
                }
            }
        }
        for(int k=0;k<rowIndex+1;++k){
            rl.add(triArray[k]);
        }
        return rl;
    }
}
0 0
原创粉丝点击