题目链接:https://leetcode-cn.com/problems/pascals-triangle-ii/description/
给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。
在杨辉三角中,每个数是它左上方和右上方的数的和。
示例:
输入: 3
输出: [1,3,3,1]
进阶:
你可以优化你的算法到 O(k) 空间复杂度吗?
class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> mlists=new ArrayList<Integer>();
int []nums=new int[rowIndex+1];
for(int i=0;i<=rowIndex;i++){
if(i==0){
nums[0]=1;
continue;
}
for(int j=rowIndex;j>=1;j--){
nums[j]=nums[j]+nums[j-1];
}
}
for(int i=0;i<nums.length;i++){
mlists.add(nums[i]);
}
return mlists;
}
}