LeetCode题目,杨辉三角Ⅱ,O(k)空间递推解法

class Solution {
public:
    vector<int> getRow(int rowIndex) {
        vector<int> ans(rowIndex+1,0);
        int temp=0;
        for(int i=0;i<=rowIndex;++i)
        {
            for(int j=0;j<=i;++j)
            {
                if(j==0||j==i) 
                {
                    ans.at(j)=1;
                    temp=ans.at(j);
                }
                else 
                {
                    ans.at(j)+=temp;
                    temp=ans.at(j)-temp;
                }
            }
        }
        
        return ans;
    }
};

 

posted @ 2020-04-25 11:02  悠远的苍穹  阅读(64)  评论(0)    收藏  举报