---
# System prepended metadata

title: 'LeetCode #119 [Pascal''s Triangle II](https://leetcode.com/problems/pascals-triangle-ii)'
tags: [LeetCode, Easy]

---

###### tags: `LeetCode` `Easy`
# LeetCode #119 [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii)
### (Easy)
給定一個非負索引 rowIndex，返回「帕斯卡三角」的第 rowIndex 行。
在「帕斯卡三角」中，每個數是它左上方和右上方的數的和。


---
與#118類似, 但只需傳回第rowIndex行即可。


---
```
class Solution {
public:
    vector<int> getRow(int rowIndex) {
        if(rowIndex){
            vector<int> tmp = {1,1};
            for(int i=1;i<=rowIndex;i++){
                vector<int> cur;
                cur.push_back(1);
                for(int j=1;j<i;j++){
                    cur.push_back(tmp[j-1]+tmp[j]);
                }
                cur.push_back(1);
                tmp=cur;
            }
            return tmp;
        }
        return {1};
    }
};
```