class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res;
if (rowIndex < 0)
return res;
res.push_back(1);
for (int i = 1; i <= rowIndex; ++i) {
vector<int> tmp;
tmp.push_back(1);
for (int j = 0; j < i - 1; ++j) {
tmp.push_back(res[j] + res[j+1]);
}
tmp.push_back(1);
res = tmp;
}
return res;
}
};
python
classSolution(object):defgetRow(self, rowIndex):"""
:type rowIndex: int
:rtype: List[int]
"""
a = [1]
for x in xrange(rowIndex):
a = [sum(i) for i in zip([0] + a, a + [0])]
return a