leetcode119
public class Solution {
public IList<int> GetRow(int rowIndex) {
List<List<int>> list = new List<List<int>>();
for (int i = ; i <= rowIndex; i++)
{
var row = new List<int>();
if (i == )
{
row.Add();
}
else if (i == )
{
row.Add();
row.Add();
}
else//i>=3
{
for (int j = ; j <= i; j++)
{
if (j == )
{
row.Add();
}
else if (j == i)
{
row.Add();
}
else
{
var pre = list[i - ];
row.Add(pre[j - ] + pre[j]);
}
}
}
list.Add(row);
}
var result = list.LastOrDefault();
return result;
}
}
https://leetcode.com/problems/pascals-triangle-ii/#/description
leetcode119的更多相关文章
- 每天一道LeetCode--119.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, ...
- [LeetCode119]Pascal's Triangle II
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...
- [Swift]LeetCode119. 杨辉三角 II | Pascal's Triangle II
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- LeetCode119.杨辉三角II
给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 3 输出: [1,3,3,1] 进阶: 你可以优化你的算法到 O ...
- LeetCode119.杨辉三角 II
119.杨辉三角 II 描述 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例 输入: 3 输出: [1,3,3,1] 进阶 ...
- LeetCode119. Pascal's Triangle II
Description Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, ...
- 2017-3-7 leetcode 66 119 121
今天纠结了一整天============================================================== leetcode66 https://leetcode.c ...
随机推荐
- java打开windows系统的浏览器
获得百度的数据有两种方式,一种是用Url从流中获得,另一种是直接打开浏览器.文字识别(OCR)后再转码可以快速百度 public static void main(String[] args) thr ...
- n人围圈报数,报3出圈
题目:有n个人围成一圈,顺序排号.从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位. Scanner scanner = new Scanner(System. ...
- 使用AspNetPager进行分页,查询条件丢失问题
在Asp.Net中使用AspNetPager进行分页时,发现一个问题: 当通过查询条件进行查询后,对查询结果进行翻页操作时,查询条件会丢失. 当修改UrlPaging属性后(设置UrlPaging=“ ...
- hdu2176nim博弈
就是要搞清楚nim博弈的原理 特别是证明方法,这一题就是第二条证明方法得出来的结论,只要a[i]^k<a[i]输出就行了 证明如下: 根据定义,证明一种判断position的性质的方法的正确性, ...
- hdu——过山车(二分图,匈牙利算法)
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- JavaScript运算符:递增和递减(++i,--i 和 i++,i-- 的区别)
递增和递减操作符直接借鉴自C,而且各有两个版本:前置型 (递增 ++i ,递减 --i )和 后置型 (递增 i++ ,递减 i-- ).书本上对两者的定义是:前置型应该位于要操作的变量之前,而后置型 ...
- 几句话概括理查德成熟度模型(RESTful)
近期做的项目中准备引入RESTful风格,特地进行了一些学习,其中比较重点的有一个理查德成熟度模型(Richardson Maturity Model),模型提出了四个等级(0-3),如下图 其中只有 ...
- 《Unity 3D游戏客户端基础框架》多线程异步 Socket 框架构建
引言: 之前写过一个 demo 案例大致讲解了 Socket 通信的过程,并和自建的服务器完成连接和简单的数据通信,详细的内容可以查看 Unity3D -- Socket通信(C#).但是在实际项目应 ...
- BZOJ4886: [Lydsy1705月赛]叠塔游戏(环套树森林&贪心)
4886: [Lydsy1705月赛]叠塔游戏 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 198 Solved: 76[Submit][Stat ...
- JavaBean和Map的相互转换
JavaBean和Map的相互转换 一.JavaBean 1.什么是JavaBean? JavaBean其实就是一种遵循特定写法的类,必须遵循一定的规范: 类必须由public修饰,并且保证有公共的无 ...