leetcode 119. 杨辉三角 II 随笔

O(k)空间O(k2)时间

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

class Solution {
public:
    vector<int> getRow(int rowIndex) {
        //O(k)空间
        vector<int> res;
        if(rowIndex<0) return res;
        res.push_back(1);
        for(int i=1;i<=rowIndex;i++){
            res.push_back(0);
            int a=0,b=0;
            for(int i=0;i<res.size();i++){
                a=b,b=res[i];
                res[i]=a+b;
            }
        }
        return res;
    }
};

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄