LeetCode OJ:Pascal's Triangle(帕斯卡三角)
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
帕斯卡三角,很简单的问题,见代码:
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ret;
vector<int> tmpVec;
ret.clear();
tmpVec.clear();
for(int i = ; i < numRows; ++i){
if(i == ){
tmpVec.push_back();
}else{
for(int j = ; j <= i; ++j){
if(j == ) tmpVec.push_back();
else if(j == i) tmpVec.push_back();
else tmpVec.push_back(ret[i - ][j - ] + ret[i - ][j]);
}
}
ret.push_back(tmpVec);
tmpVec.clear();
}
return ret;
}
};
LeetCode OJ:Pascal's Triangle(帕斯卡三角)的更多相关文章
- LeetCode OJ——Pascal's Triangle II
http://oj.leetcode.com/problems/pascals-triangle-ii/ 杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algo ...
- LeetCode OJ——Pascal's Triangle
http://oj.leetcode.com/problems/pascals-triangle/ 杨辉三角 先分析数据,找出规律 ans[row][col] = ans[row-1][col-1]+ ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- [LeetCode] 119. Pascal's Triangle II 杨辉三角 II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- 【LeetCode】Pascal's Triangle II 解题报告
[LeetCode]Pascal's Triangle II 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/pascals-tr ...
- [LeetCode] 119. 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 ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- [Leetcode][JAVA] Pascal's Triangle I, II
Pascal's Triangle: Given numRows, generate the first numRows of Pascal's triangle. For example, give ...
- Pascal's Triangle(帕斯卡三角)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 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, ...
随机推荐
- Angular学习笔记—路由(转载)
创建路由 1.首先安装 Angular Router.你可以通过运行以下任一操作来执行此操作: yarn add @angular/router # OR npm i --save @angular/ ...
- TypeScript学习笔记—函数
函数定义 在 JavaScript 中,有两种常见的定义函数的方式——函数声明(Function Declaration)和函数表达式(Function Expression): // 函数声明(Fu ...
- Linux命令详情
- 人性化的Form(django)
django中的Form一般有两种功能: 输入html 验证用户输入 html: <!DOCTYPE html> <html lang="en"> < ...
- window下rails4.1 发生TZInfo::DataSourceNotFound 错误
在官网上学习rails 4.1 ,启动rails server之后发生了如下错误 $ rails serverBooting WEBrickRails 4.1.0 application starti ...
- cdoj1325卿学姐与基本法
地址:http://acm.uestc.edu.cn/#/problem/show/1325 题目: 卿学姐与基本法 Time Limit: 2000/1000MS (Java/Others) ...
- Hbase 布隆过滤器BloomFilter介绍
转载自:http://blog.csdn.net/opensure/article/details/46453681 1.主要功能 提高随机读的性能 2.存储开销 bloom filter的数据存在S ...
- strtok()函数、fseek()函数、fwrite()函数、fread()函数的使用
在电子词典这个项目过程中遇到了几个主要的问题,第一个是怎么解决把翻译分开这个.第二个事情就是怎么把结构体写到文件中.这两个问题,一个是关于字符串的操作一个是关于文件的操作. strtok函数 char ...
- [转]毕设- 深入HBase架构解析(二)
深入HBase架构解析(二) 前言 这是<深入HBase架构解析(一)>的续,不多废话,继续.... HBase读的实现 通过前文的描述,我们知道在HBase写时,相同Cell(RowKe ...
- 数字图像处理,图像锐化算法的C++实现
http://blog.csdn.net/ebowtang/article/details/38961399 之前一段我们提到的算法都是和平滑有关, 经过平滑算法之后, 图像锐度降低, 降低到一定程度 ...