首页 > 代码库 > 119. Pascal's Triangle II

119. Pascal's Triangle II

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

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

Note:
Could you optimize your algorithm to use only O(k) extra space?

 此题没什么好讲的,直接代码:

 

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Helvetica Neue"; color: #454545 }</style>

public class Solution {

    public List<Integer> getRow(int rowIndex) {

        List<Integer> res = new ArrayList<>();

        for(int i=0;i<=rowIndex;i++){

            res.add(0,1);

            for(int j=1;j<res.size()-1;j++){

                res.set(j,res.get(j)+res.get(j+1));

            }

        }

        return res;

    }

}

 
 

119. Pascal's Triangle II