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 ...
随机推荐
- POI解析excel格式的文件(xls,xlsx)
先贴出所需的jar包: 1.poi-3.17-beta1.jar 2.poi-ooxml-3.17-beta1.jar 3.poi-ooxml-schemas-3.17-beta1.jar 4.com ...
- 记录一次服务器CPU 100%的解决过程
昨天客户反馈业务系统很慢,而且偶尔报错. 查看nginx日志: [root@s2 nginx]# tail log/error.log 2017/03/14 12:54:46 [error] 1704 ...
- arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf等的区别
博客来之于: http://www.veryarm.com/296.html 命名规则: 交叉编译工具链的命名规则为:arch [-vendor] [-os] [-(gnu)eabi] arch - ...
- $.each()与$(selector).each()
$.each()与$(selector).each()不同, 后者专用于jquery对象的遍历, 前者可用于遍历任何的集合(无论是数组或对象),如果是数组,回调函数每次传入数组的索引和对应的值(值亦可 ...
- 如何快速配好java环境变量和查看电脑上安装JDK的版本位数
今天一个新手在群里问自己的Eclipse打不开,然后我是属于那种热心肠的人,一般自己知道的就会告诉他们,看了下,是环境变量没有配好,反正我觉得配环境比较简单,现在就教大家简单的环境变量配法 path ...
- tiny4412-Uboot启动分析
一.从本质上将,引导转载程序至少应提供以下功能 (1)设置和初始化RAM (2)初始化一个串口 (3)检测机器类型(machine type) (4)设置内核标签列表(tag list) (5)调用内 ...
- stenciljs 学习十一 pwa 支持
stenciljs 对于pwa 的支持是自动注入的,我们只需要简单的配置,stenciljs使用workbox 配置 默认配置 { skipWaiting: true, clientsClaim: t ...
- APP自动化测试各项指标分析
一.内存分析专项 启动App. DDMS->update heap 操作app,点几次GC dump heap hprof-conv转化 MAT分析 二.区分几种内存 VSS- Virtual ...
- HIVE之 Sqoop 1.4.6 安装、hive与oracle表互导
1. sqoop数据迁移 1.1 概述 sqoop是apache旗下一款“Hadoop和关系数据库服务器之间传送数据”的工具. 导入数据:MySQL,Oracle导入数据到Hadoop的HDFS.HI ...
- mac 使用
普通键盘操作mac电脑,快捷键: 快捷键 功能 ctrl + a 到行首 ctrl + e 到行尾 ctrl + up 打开任务控制(窗口平铺) window + tab 选择任务 ctrl + le ...