119. Pascal's Triangle II

xiaoxiao2021-02-28  104

题意:求杨辉三角的某一层。

思路:利用二项式组合公式,在O(n*n)内解决。

class Solution { public: vector<int> getRow(int rowIndex) { vector<int> A(rowIndex+1, 0); A[0] = 1; for(int i=1; i<rowIndex+1; i++) for(int j=i; j>=1; j--) A[j] += A[j-1]; return A; } };

转载请注明原文地址: https://www.6miu.com/read-18231.html

最新回复(0)