LeetCode119. Pascal's Triangle II
Description
Given an index k, return the kth row of the Pascal’s triangle.
For example, given k = 3,
Return [1,3,3,1].
my program
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res = {1};
for(int i = 1; i<=rowIndex; i++)
{
res.push_back(0);
for(int j = res.size(); j>0; j--)
{
res[j] += res[j-1];
}
}
return res;
}
};
34 / 34 test cases passed.
Status: Accepted
Runtime: 0 ms
other methods
vector<int> getRow(int rowIndex) {
vector<int> ans(rowIndex+1,1);
int small = rowIndex/2;
long comb = 1;
int j = 1;
for (int i=rowIndex; i>=small; i--){
comb *= i;
comb /= j;
j ++;
ans[i-1] = (int)comb;
ans[j-1] = (int)comb;
}
return ans;
}
LeetCode119. Pascal's Triangle II的更多相关文章
- 每天一道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 [ ...
- 28. Triangle && Pascal's Triangle && Pascal's Triangle II
Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to a ...
- 【LeetCode】118 & 119 - Pascal's Triangle & Pascal's Triangle II
118 - Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...
- Pascal's Triangle,Pascal's Triangle II
一.Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, giv ...
- 杨辉三角形II(Pascal's Triangle II)
杨辉三角形II(Pascal's Triangle II) 问题 给出一个索引k,返回杨辉三角形的第k行. 例如,给出k = 3,返回[1, 3, 3, 1] 注意: 你可以优化你的算法使之只使用O( ...
- LeetCode OJ 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, ...
- 118/119. Pascal's Triangle/II
原文题目: 118. Pascal's Triangle 119. Pascal's Triangle II 读题: 杨辉三角问题 '''118''' class Solution(object): ...
- LeetCode: Pascal's Triangle II 解题报告
Pascal's Triangle II Total Accepted: 19384 Total Submissions: 63446 My Submissions Question Solution ...
随机推荐
- 求同余方程x^A=B(mod m)的解个数(原根与指标)
求方程:的解个数 分析:设,那么上述方程解的个数就与同余方程组:的解等价. 设同于方程的解分别是:,那么原方程的解的个数就是 所以现在的关键问题是求方程:的解个数. 这个方程我们需要分3类讨论: 第一 ...
- EF 通用数据层父类方法小结
MSSql 数据库 数据层 父类 增删改查: using System;using System.Collections.Generic;using System.Data;using System. ...
- 图解http读书笔记
以前对HTTP协议一知半解,一直不清楚前端需要对于HTTP了解到什么程度,知道接触的东西多了,对于性能优化.服务端的配合和学习中也渐渐了解到了HTTP基础的重要性,看了一些大神对HTTP书籍的推荐,也 ...
- vs 代理登入
https://msdn.microsoft.com/zh-cn/vstudio/dn771556.aspx
- DELPHI MAKEWORD的用法
WORD MAKEWORD( BYTE bLow, // low-order byte of short value BYTE bHigh // high-order byte of ...
- saltstack之salt event事件用法
event是一个本地的ZeroMQ PUB Interface,event是一个开放的系统,用于发送信息通知salt或其他的操作系统.每个event都有一个标签.事件标签允许快速制定过滤事件.除了标签 ...
- python 未发现数据源名称并且未指定默认驱动程序
最近在用python连接sqlserver读取数据库,读取数据时候在本机电脑正常,但是把程序部署到服务器运行时一直报错“未发现数据源名称并且未指定默认驱动程序”,后来发现是因为数据源的问题,解决如下: ...
- vue总结介绍
转自(https://zhuanlan.zhihu.com/p/23078117) 模板语法 Vue 提供了一堆数据绑定语法. {{ text }} 文本插值 <div v-html=" ...
- mongodb 踩坑记录
Map-Reduce Map-Reduce 是 mongodb 处理批量数据的大杀器,凡是数据量大并且定时处理能满足需求的,都可以试着扔给 mongodb,让它去 Map-Reduce. 以下截取自文 ...
- C# 多线程控制 通讯
一.多线程的概念 Windows是一个多任务的系统,如果你使用的是windows 2000及其以上版本,你可以通过任务管理器查看当前系统运行的程序和进程.什么是进程呢?当一个程序开始运行时,它就是一 ...