Pascal's Triangle,Pascal's Triangle II
一.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>> res;
- if(numRows==){
- return res;
- }
- vector<int> row;
- int size = ;
- while(numRows--){
- int x = 1;for(int i=;i<size;i++){
- int y = row[i];
- row[i]= x+y;
- x = y;
- }
- row.push_back();
- res.push_back(row);
- size++;
- }
- return res;
- }
- };
二.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,3,1]
.
- class Solution {
- public:
- vector<int> getRow(int rowIndex) {
- rowIndex+=;
- vector<int> row;
- int size = ;
- while(rowIndex--){
- int x = ;
- for(int i=;i<size;i++){
- int y = row[i];
- row[i] = x+y;
- x=y;
- }
- row.push_back();
- size++;
- }
- return row;
- }
- };
Pascal's Triangle,Pascal's Triangle II的更多相关文章
- 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, ...
- LeetCode Pascal's Triangle && Pascal's Triangle II Python
Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, given ...
- LeetCode Pascal's Triangle Pascal三角形
题意:给一个数字,返回一个二维数组,包含一个三角形. 思路:n=0.1.2都是特例,特别处理.3行以上的的头尾都是1,其他都是依靠上一行的两个数.具体了解Pascal三角形原理. class Solu ...
- pascal+sublime搭建Pascal学习环境
一.fpc安装 1. 下载:http://www.freepascal.org/down/i386/win32.var(或者:http://download.csdn.net/detail/wenph ...
- leetcode 118. Pascal's Triangle 、119. Pascal's Triangle II 、120. Triangle
118. Pascal's Triangle 第一种解法:比较麻烦 https://leetcode.com/problems/pascals-triangle/discuss/166279/cpp- ...
- [leetcode] 2. Pascal's Triangle II
我是按难度往下刷的,第二道是帕斯卡三角形二.简单易懂,题目如下: Given an index k, return the kth row of the Pascal's triangle. For ...
- leetcode 【 Pascal's Triangle II 】python 实现
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...
- leetcode—pascal triangle
1.题目描述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
随机推荐
- 自定义view(自定义view的时候,三个构造函数各自的作用)
package com.timeshare.tmband.Utils; import android.content.Context; import android.content.res.Typed ...
- 常用的SQL数据库语句总结
1as 的用处 as可以对表和列取别名 在开发过程中经常遇到开始给某一个的字段去field1的名称,但后来有感觉field1字段指定不确切,于是又把此字段改成了field2,由于开始认 为field1 ...
- linux学习笔记之进程间通信
一.基础知识. 1:进程通信基础(interProcess Communication, IPC):管道,FIFO(命名管道),XSI IPC,POSIX 信号量. 2:管道. 1,缺陷. 1)部分系 ...
- jQuery + css 公告从左往右滚动
$(function() { // 公告滚动 $(".notice-content").textScroll(); }); /** * 从右往左滚动文字 * @returns {u ...
- Github获取仓库最新Release版本号API
package me.chunsheng.hongbao.utils; import android.content.Context; import android.content.Intent; i ...
- shopnc数据库 批量修改商品价格
1.商品价格统一上调50 2.商品价格个别上调50 UPDATE `nc_goods` SET `goods_price` = `goods_price` +50 where goods_id!=10 ...
- openstack安装记录(二)keystone安装
先决条件 在你配置 OpenStack 身份认证服务前,你必须创建一个数据库和管理员令牌. 完成下面的步骤以创建数据库: 用数据库连接客户端以 root 用户连接到数据库服务器: $ mysql -u ...
- NDK 的helloworld步奏
1. helloworld.c #include <string.h> #include <jni.h> /* * Class: com_example_ndk_NativeH ...
- Android中Handle详解
上图为本人总结的Handler,网上发现一片总结很好的博客就copy过来:作为参考 Handler有何作用?如何使用? 一 .Handler作用和概念 包含线程队列和消息队列,实现异步的消息处理机制, ...
- Oracle ORA-01555(快照过旧)
一.引言: [oracle@yft yft]$ oerr ora 01555 01555, 00000, "snapshot too old: rollback segment number ...