题目:

Given numRows, generate the first numRows of Pascal's triangle.

For example, given numRows = 5,
Return

[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
计算杨辉三角(帕斯卡三角)

代码:

class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> vec1;
for(int i = ; i < numRows; ++i)
{
vector<int> vec2;
vec2.push_back();
for(int j = ; j < i; ++j)
{
int tmp = vec1[i-][j-] + vec1[i-][j];
vec2.push_back(tmp);
}
if(i != )
vec2.push_back();
vec1.push_back(vec2);
}
return vec1;
}
};

[LeetCode118]Pascal's Triangle的更多相关文章

  1. 每天一道LeetCode--118. Pascal's Triangle(杨辉三角)

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  2. [leetcode-118]Pascal's triangle 杨辉三角

    Pascal's triangle (1过) Given numRows, generate the first numRows of Pascal's triangle. For example, ...

  3. LeetCode118. Pascal's Triangle 杨辉三角

    题目 给定行数,生成对应的杨辉三角 思考 同一行是对称的,最大的下标为(行数+1)/2;1,1,2,3,6;下标从0开始,则对应分别为0.0.1.1.2.2 对于第偶数行,个数也是偶数,对于奇数行,个 ...

  4. [Swift]LeetCode118. 杨辉三角 | Pascal's Triangle

    Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's t ...

  5. LeetCode118:Pascal&#39;s Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  6. [LeetCode] 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, ...

  7. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  8. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  9. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

随机推荐

  1. hdu4521 小明系列的问题——小明序列(LIS变种 (段树+单点更新解决方案))

    链接: huangjing 题目:中文题目 思路: 1:这个题目假设去掉那个距离大于d的条件,那么必定是一个普通的LIS.可是加上那个条件后就变得复杂了.我用的线段树的解法. . .就是採用延迟更新的 ...

  2. hdu 4620 Fruit Ninja Extreme(状压+dfs剪枝)

    对t进行从小到大排序(要记录ID),然后直接dfs. 剪枝的话,利用A*的思想,假设之后的全部连击也不能得到更优解. 因为要回溯,而且由于每次cut 的数目不会超过10,所以需要回溯的下标可以利用一个 ...

  3. Winsock 编程流程

    近期看了<Window程序设计>感觉在网络方面讲的不错,讲的非常通俗易懂.与大家一同交流 转载请注明出处:http://blog.csdn.net/u010484477谢谢^_^ 使用 W ...

  4. LDA主题模型学习笔记3.5:变分參数推导

    如今来推导一下得到变分參数更新式的过程.这一部分是在论文的附录中,为避免陷入过多细节而影响总体理解.能够在刚開始学习LDA的时候先不关注求解细节.首先要把L写成关于γ,ϕ\gamma,\phi函数.依 ...

  5. centos7图形配置 firewall-config

    图形配置 firewall-config centos 7:systemctl stop firewalld.service #停止

  6. BNUOJ34973Liserious战队

    Liserious战队 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class ...

  7. java 采用MD5加密解密

    MD5加密解密 package endecrypt; import java.io.UnsupportedEncodingException; import java.security.Message ...

  8. Luci - UCI (Unified Configuration Interface)

    参考: http://wiki.openwrt.org/doc/techref/uc http://luci.subsignal.org/api/luci/modules/luci.model.uci ...

  9. ibatis dynamic的用法

    <select id="idididid" resultClass="java.uitl.HashMap" parameterClass="ja ...

  10. jps查看java进程中哪个线程在消耗系统资源

    jps或ps -ef|grep java可以看到有哪些java进程,这个不用说了.但值得一提的是jps命令是依赖于/tmp下的某些文件 的. 而某些操作系统,定期会清理掉/tmp下的文件,导致jps无 ...