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 ...
随机推荐
- uva-1636-概率
https://vjudge.net/problem/UVA-1636 给出一个左轮手枪的弹夹串,第一枪是空的,问是继续打还是转一转再打下一枪还为空的概率大.继续打为空的概率就是 '00'的个数比上' ...
- 牛客网——F求最大值
链接:https://www.nowcoder.net/acm/contest/29/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...
- python re 正则表达式复习
正则表达式是一种小巧的独立语言,用于字符串的匹配 一.元字符 1.. 匹配除换行符外的任意字符 2.^ 匹配字符串开头 3.$ 匹配字符串末尾 4.* 匹配前一字符n次 5.+ 匹配前一字符1-n次 ...
- javascript递归导致的堆栈溢出
function foo() {foo(); //setTimeout(foo, 0); } foo() 原因是每次执行代码时,都会分配一定尺寸的栈空间(Windows系统中为1M),每次方法调用 ...
- 用于调试的printf函数和自定义log函数
1. 用宏定义调试用的DPRINT #define DEBUG_ENABLE #ifdef DEBUG_ENABLE #define DPRINT(fmt, args...) fprintf(stde ...
- 使用c++实现一个FTP客户端(三)
接上篇:http://www.cnblogs.com/jzincnblogs/p/5217688.html,这篇主要记录编程过程中需要注意的地方以及遇到的一些问题及解决方法. 一.gethostbyn ...
- Mysql的日期转换成星期[某天对应周几]
|—— 应用中会有各种不同的需求,要灵活应对:比如拿到某一日期要知道是周几 |——DAYOFWEEK(date) [返回日期date的星期索引(1=星期天,2=星期一, ……7=星期六).这些索引值对 ...
- Nginx 设置rewrite规则是遇到的一个{}大括号引发的报错问题
一个群友提到: 用nginx image_filter模块裁图,用!拼宽高能够实现,现在想用参数传宽高总是报错,配置如下: location ~ ^/images/.* { if ( $q ...
- MyBatis_Study_001(入门)
1.话不多说,直接搞起; (源码地址https://github.com/carryLess/mbtsstd-001) 2.去官网https://github.com/mybatis下载文件 下载完成 ...
- 设计模式(Python)-策略模式
本系列文章是希望将软件项目中最常见的设计模式用通俗易懂的语言来讲解清楚,并通过Python来实现,每个设计模式都是围绕如下三个问题: 为什么?即为什么要使用这个设计模式,在使用这个模式之前存在什么样的 ...