2017.11.14 LeetCode
来源:互联网 发布:个人发卡网源码授权 编辑:程序博客网 时间:2024/06/05 07:11
最近很忙,又有期中考试,事偏多,耽误了几天,下次一定要注意,加油!
118. Pascal’s Triangle
Description
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> > res; vector<int> t; for(int i = 0;i < numRows;i++) { t.push_back(1); for(int j = 1;j < i;j++) { int s = res[i-1][j-1] + res[i-1][j]; t.push_back(s); } if(i > 0) t.push_back(1); res.push_back(t); t.clear(); } return res; }};
119. 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].
Note:
Could you optimize your algorithm to use only O(k) extra space?
题意 : 打印第杨辉三角中的第k+1行
分析: 根据组合数中的性质,我们知道 C(n,m) = C(n,m-1)*(n-m+1)/m,直接根据公式即可
参考函数
class Solution {public: vector<int> getRow(int rowIndex) { vector<int> res(rowIndex+1); res[0] = 1; for(int i = 1;i <= rowIndex;i++) { long long t = (int)res[i-1]*1ll*(rowIndex-i+1)/i; res[i] = t; } return res; }};
阅读全文
0 0
- 2017.11.14 LeetCode
- leetcode 14
- Leetcode(14)
- LeetCode(14)
- leetcode-14
- 2017.11.1 LeetCode
- 2017.11.2 LeetCode
- 2017.11.3 LeetCode
- 2017.11.4 LeetCode
- 2017.11.5 LeetCode
- 2017.11.9 LeetCode
- 2017.11.21 LeetCode
- 2017.11.22 LeetCode
- LeetCode (14) Plus One
- leetcode #14 LongestCommenPrefix
- my leetcode#13 #14
- Leetcode #14 in cpp
- Leetcode no. 14
- 分布式事务:不过是在一致性、吞吐量和复杂度之间,做一个选择 分布式系统 消息系统
- 音乐播放
- 比较两个数据的大小
- Constraint Checker hiho一下第176周
- 如何使用OpenCV来锐化图像
- 2017.11.14 LeetCode
- 数据结构学习之整体二分&&bzoj2738矩阵乘法题目分析
- 简单介绍区块链技术
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.tdb_
- 自定义provider服务
- Mybatis基本配置、日志文件(sql语句)打印
- 使用SpringMvc跨服务器上传图片,Ajax异步刷新图片框显示图片功能请求不到后台,onChange事件没有激活的源码?
- 160
- 简单模拟Build设计模式