问题描述:
Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal’s triangle.
In Pascal’s triangle, each number is the sum of the two numbers directly above it as shown:
利用杨辉三角和组合数的关系求解:
//(N choose K+1) = (N choose K) * (N-K)/(K+1)
//the ith row has i+1 elements from 0 to i
class Solution {
//(N choose K+1) = (N choose K) * (N-K)/(K+1)
//the ith row has i+1 elements from 0 to i
public List<Integer> getRow(int rowIndex) {
List<Integer> myList = new ArrayList<>();
for (int i=0; i<=rowIndex; i++){
if (i==0) myList.add(1);
else{
myList.add((int) ((myList.get(myList.size() - 1) * (long) (rowIndex - i + 1)) / i));
}
}
return myList;
}
}