代码如下: 1 vector<int> getRow(int rowIndex) { 2 vector<int> dp(rowIndex + 1,0); 3 dp[0] = 1; 4 for(int i = 1;i <= rowIndex;i++) 5 { 6 for(int j = i;j >= 1;j--) 7 { 8 dp[j]+=dp[j - 1]; 9 } 10 } 11 return dp; 12 } 分类: leetcode 好文要顶...
2、 Given an indexk, return thekth row of the Pascal's triangle. For example, givenk= 3, Return[1,3,3,1]. Note: Could you optimize your algorithm to use onlyO(k) extra space?这道题跟Pascal's Triangle很类似,只是这里只需要求出某一行的结果。Pascal's Triangle中因为是求出全部结果,所...
public: vector<int> getRow(int rowIndex) { vector<vector<int>> res; vector<int> temp; //把第一行放进去 temp.push_back(1); res.push_back(temp); if (rowIndex == 0) return res[0]; //从第二行开始依次生成 int r = 1; while (r <= rowIndex) { vector<int> temp(r+1); temp...
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? classSolution(object): defgetRow(self,rowIndex): """ :type rowIndex: int :rtype: List[int] ""...
题目描述 Given an index k, return the k th row of the Pascal's triangle.For example, given ...
Each row forms the corresponding exponent of 11 after performing a simple modification. You can derive the Fibonacci series from the triangular pattern. Coloring all the odd numbers and even numbers different colors produces a visual pattern known as the Sierpinski triangle....
The triangle can be constructed by first placing a 1 (Chinese “—”) along the left and right edges. Then the triangle can be filled out from the top by adding together the two numbers just above to the left and right of each position in the triangle. Thus, the second row, inHindu...
119. 杨辉三角 II - 给定一个非负索引 rowIndex,返回「杨辉三角」的第 rowIndex 行。 在「杨辉三角」中,每个数是它左上方和右上方的数的和。 [https://pic.leetcode-cn.com/1626927345-DZmfxB-PascalTriangleAnimated2.gif] 示例 1: 输入: rowIndex = 3 输出: [1,
* Given an index k, return the k th 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? */ publicclassMain54 { publicstaticvoidmain(String[] args) { ...
问题https://leetcode-cn.com/problems/pascals-triangle-ii/ 练习使用JavaScript解答 /** * @param {number} rowIndex * @return {number[]} */ var getRow = function(rowIndex) { var arr = [1], t1, t2; for(var i=1;i<=rowIndex;++i) { ...