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?
public class Solution {
public List<Integer> getRow(int rowIndex) {
int size=rowIndex+1;
ArrayList<Integer> a=new ArrayList<Integer>(size);
for(int i=0;i<size;i++) a.add(0);
a.set(0,1);
int prev=0,curr=0;
for(int i=1;i<size;i++){
prev=1;
for(int j=1;j<=i;j++){
curr=a.get(j);
a.set(j,curr+prev);
prev=curr;
}
}
return a;
}
}