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, ...
随机推荐
- Keras网络层之常用层Core
常用层 常用层对应于core模块,core内部定义了一系列常用的网络层,包括全连接.激活层等 Dense层 keras.layers.core.Dense(units, activation=None ...
- Android之网络----使用HttpClient发送HTTP请求(通过get方法获取数据)
[正文] 一.HTTP协议初探: HTTP(Hypertext Transfer Protocol)中文 "超文本传输协议",是一种为分布式,合作式,多媒体信息系统服务,面向应用层 ...
- 查看Oracle的表中有哪些索引
用user_indexes和user_ind_columns系统表查看已经存在的索引 对于系统中已经存在的索引我们可以通过以下的两个系统视图(user_indexes和user_ind_columns ...
- Python:笔记(4)——高级特性
Python:笔记(4)——高级特性 切片 取一个list或tuple的部分元素是非常常见的操作.Python提供了切片操作符,来完成部分元素的选取 除了上例简单的下标范围取元素外,Python还支持 ...
- SqlHelper简单实现(通过Expression和反射)2.特性和实体设计
对于需求中的不要暴露DataTable或DataSet,我想到了设计中常用的对象:实体(Entity),通过实体将数据库中的字段封装成类,这样做不仅使代码更有可读性,维护起来也很方便.同时我自定义了一 ...
- $python正则表达式系列(3)——正则内置属性
本文主要总结一下python正则的一些内置属性的用法. 1. 编译标志:flags 首先来看一下re.findall函数的函数原型: import re print('[Output]') print ...
- Sybase:解锁
Sybase:解锁 Sql代码: --查询锁表 sp_iqlocks --解除锁定 drop connection[连接序号]
- samba 4.7.16 安装配置详解
系统:Centos 7.4 x64位 服务版本:samba-4.7.1.samba-client-4.7 Samba 简介 Samba 是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服 ...
- 20145201 《Java程序设计》第二周学习总结
20145201 <Java程序设计>第二周学习总结 教材学习内容总结 本周学习了课本第三章内容,即JAVA基础语法. 3.1 类型.变量与运算符 基本类型:在java中基本类型主要可区分 ...
- APPIUM API整理(python)---元素查找
最近在学习自动化框架appium,网上找一些API相关资料整理了一下 1.find_element_by_id find_element_by_id(self, id_): Finds element ...