LetCode 119. 杨辉三角 II

class Solution {
public:
    vector<int> getRow(int rowIndex) {
        if (rowIndex == 0)
            return vector<int>(1, 1);
        vector<int> res(rowIndex + 1, 0);
        res[0] = 1;
        // 从后往前覆盖上一行的数据,以免冲突
        for (int i = 1; i <= rowIndex; ++i){
            res[i] = 1;
            for (int j = i - 1; j > 0; --j)
                res[j] = res[j - 1] + res[j];
        }
        return res;
    }
};
static int x=[](){
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    return 0;
}();

猜你喜欢

转载自blog.csdn.net/wbb1997/article/details/81089420
今日推荐