leetcode118
public class Solution {
public IList<IList<int>> Generate(int numRows) {
var list = new List<IList<int>>();
for (int i = ; i < numRows; i++)
{
var row = new List<int>();
if (i == )
{
row.Add();
}
else if (i == )
{
row.Add();
row.Add();
}
else
{
var prerow = list[i - ].ToList();
for (int j = ; j <= i; j++)
{
if (j == )
{
row.Add();
}
else if (j == i)
{
row.Add();
}
else
{
row.Add(prerow[j - ] + prerow[j]);
}
}
}
list.Add(row);
}
return list;
}
}
https://leetcode.com/problems/pascals-triangle/#/description
leetcode118的更多相关文章
- 每天一道LeetCode--118. Pascal's Triangle(杨辉三角)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- [LeetCode118]Pascal's Triangle
题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,R ...
- [Swift]LeetCode118. 杨辉三角 | Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's t ...
- [leetcode-118]Pascal's triangle 杨辉三角
Pascal's triangle (1过) Given numRows, generate the first numRows of Pascal's triangle. For example, ...
- LeetCode118.杨辉三角
给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 5 输出: [ [1], [1,1], [1,2,1], [ ...
- LeetCode118:Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- LeetCode118 杨辉三角 Python
给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 示例:输入: 5 输出: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] cl ...
- LeetCode118. Pascal's Triangle 杨辉三角
题目 给定行数,生成对应的杨辉三角 思考 同一行是对称的,最大的下标为(行数+1)/2;1,1,2,3,6;下标从0开始,则对应分别为0.0.1.1.2.2 对于第偶数行,个数也是偶数,对于奇数行,个 ...
- 2017-3-6 leetcode 118 169 189
今天什么都没发生 ================================================= leetcode118 https://leetcode.com/problems ...
随机推荐
- 《DSP using MATLAB》Problem 3.21
模拟信号经过不同的采样率进行采样后,得到不同的数字角频率,如下: 三种Fs,采样后的信号的谱 重建模拟信号,这里只显示由第1种Fs=0.01采样后序列进行重建,采用zoh.foh和spline三种方法 ...
- windows 版nginx 的一些基础知识
nginx的Windows版本使用原生Win32 API(非Cygwin模拟层).当前nginx/Windows只使用select作为通知方法,所以不要期待它有很高的性能和扩展性.鉴于这点和一些已知问 ...
- TensorFlow学习线路
如何高效的学习 TensorFlow 代码? 或者如何掌握TensorFlow,应用到任何领域? 作者:黄璞链接:https://www.zhihu.com/question/41667903/ans ...
- 消息队列在VB.NET数据库开发中的应用
我们先简单的了解一下什么是消息队列(MSMQ)?消息队列是 Windows 2000(NT也有MSMQ,WIN95/98/me/xp不含消息队列服务但是支持客户端的运行)操作系统中通讯的基础,也是用于 ...
- Git中特别的命令
Rebase 假设我们的分支结构如下: rebase 会把从 Merge Base 以来的所有提交,以补丁的形式一个一个重新达到目标分支上.这使得目标分支合并该分支的时候会直接 Fast Forwar ...
- bzoj 3687 简单题——bitset
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3687 关于 bitset :https://blog.csdn.net/snowy_smil ...
- 浅谈fhq_treap
\(BST\) 二叉查找树,首先它是一颗二叉树,其次它里面每个点都满足以该点左儿子为根的子树里结点的值都小于自己的值,以该点右儿子为根的子树里结点的值都大于自己的值.如果不进行修改,每次查询都是\(O ...
- VBox修改uuid
1.使用VBoxManage命令时,需要先在命令行中切换到VirtualBox的安装目录下 2.修改vdi的uuid:VBoxManage internalcommands sethduuid D: ...
- OpenFileDialog 打开快捷方式时,返回的是快捷方式引用的路径,而不是快捷方式(.lnk)自身的路径
OpenFileDialog 打开 .lnk 文件. OpenFileDialog 有个DereferenceLinks 属性:获取或设置一个值,该值指示文件对话框是返回快捷方式引用的文件的位置,还是 ...
- PHP中imagecopyresampled参数详解
原文链接http://blog.csdn.net/ajaxchen_615/article/details/5941181 做php缩微图程序,用到了imagecopyresampled函数,在网上找 ...