Posted on

Description

Submission

class Solution {
public:
    vector<int> getRow(int rowIndex) {
        if(rowIndex == 0) return {1};
        vector<int> res {1, 1};
        if(rowIndex == 1) return res;
        for(int i = 2; i <= rowIndex; ++i) {
            int prevNum = res[0];
            for(int j = 1; j < res.size(); ++j) {
                int tmp = res[j];
                res[j] += prevNum;
                prevNum = tmp;
            }
            res.push_back(prevNum);
        }
        return res;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *