Leetcode - Pascal's Triangle II

题目链接

Pascal's Triangle II

Given an index k, return the kth
row of the Pascal's triangle.
For example, given k = 3,Return [1,3,3,1]
.
Note:Could you optimize your algorithm to use only O(k) extra space?

解题思路

TODO (稍后补充)

解题代码

class Solution {
public:
    vector<int> getRow(int rowIndex) {
        vector<int> op(rowIndex+1, 0);
        op[0]=1;
        for (int i=1;i<=rowIndex;i++) {
            for (int k=i;k>=1;k--) {
               op[k] = op[k] + op[k-1]; 
            }
            
        }
        return op;
        
    }
};
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容