LeetCode (Pascal's Triangle)
来源:互联网 发布:淘宝商品布光技巧 编辑:程序博客网 时间:2024/06/14 01:58
Problem:
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]]
Solution:class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>> ans; if(numRows == 0) return ans; if(numRows == 1) return {{1}}; ans = generate(numRows - 1); vector<int> tmp, last = ans.back(); tmp.push_back(1); for(int i = 0; i < last.size() - 1; i++){ tmp.push_back(last[i] + last[i + 1]); } tmp.push_back(1); ans.push_back(tmp); return ans; }};
阅读全文
0 0
- 【Leetcode】Pascal's Triangle (Pascal)
- LeetCode Pascal's Triangle
- [Leetcode] Pascal's Triangle
- LeetCode: Pascal's Triangle
- [LeetCode] Pascal's Triangle
- 【leetcode】Pascal's Triangle
- LeetCode - Pascal's Triangle
- [LeetCode]Pascal's Triangle
- Leetcode: Pascal's Triangle
- Pascal's Triangle --Leetcode
- LeetCode-Pascal's Triangle
- [leetcode] Pascal's Triangle
- LeetCode - Pascal's Triangle
- 【leetcode】Pascal's Triangle
- LeetCode | Pascal's Triangle
- Pascal's Triangle -leetcode
- [leetcode]Pascal's Triangle
- Leetcode Pascal's Triangle
- 怎样添加earlysuspend到一个普通驱动中
- git commit ammend 修改已经提交的注释
- CSS基础-定位
- Java中时间比较大小
- MATLAB绘图
- LeetCode (Pascal's Triangle)
- 使用包setup.py安装
- 使用Java实现简单串口通信
- 深度学习汇报系列:(二)线性代数
- Redis GEO 特性
- c++ vertor容器
- 单例模式(Singleton)(对象创建型模式)
- 学习篇JAVA之接口和抽象类
- 集成支付宝 报错:rsa_private read error : private key is NULL