一.Pascal's Triangle

Given numRows, generate the first numRows of Pascal's triangle.

For example, given numRows = 5,
Return

  1. [
  2. [1],
  3. [1,1],
  4. [1,2,1],
  5. [1,3,3,1],
  6. [1,4,6,4,1]
  7. ]
  1. class Solution {
  2. public:
  3. vector<vector<int>> generate(int numRows) {
  4. vector<vector<int>> res;
  5. if(numRows==){
  6. return res;
  7. }
  8. vector<int> row;
  9. int size = ;
  10. while(numRows--){
  11. int x = 1;for(int i=;i<size;i++){
  12. int y = row[i];
  13. row[i]= x+y;
  14. x = y;
  15. }
  16. row.push_back();
  17. res.push_back(row);
  18. size++;
  19. }
  20. return res;
  21. }
  22. };

二.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].

  1. class Solution {
  2. public:
  3. vector<int> getRow(int rowIndex) {
  4. rowIndex+=;
  5. vector<int> row;
  6. int size = ;
  7. while(rowIndex--){
  8. int x = ;
  9. for(int i=;i<size;i++){
  10. int y = row[i];
  11. row[i] = x+y;
  12. x=y;
  13. }
  14. row.push_back();
  15. size++;
  16. }
  17. return row;
  18. }
  19. };

Pascal's Triangle,Pascal's Triangle II的更多相关文章

  1. 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 ...

  2. 【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, ...

  3. 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 ...

  4. LeetCode Pascal's Triangle Pascal三角形

    题意:给一个数字,返回一个二维数组,包含一个三角形. 思路:n=0.1.2都是特例,特别处理.3行以上的的头尾都是1,其他都是依靠上一行的两个数.具体了解Pascal三角形原理. class Solu ...

  5. pascal+sublime搭建Pascal学习环境

    一.fpc安装 1. 下载:http://www.freepascal.org/down/i386/win32.var(或者:http://download.csdn.net/detail/wenph ...

  6. 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- ...

  7. [leetcode] 2. Pascal's Triangle II

    我是按难度往下刷的,第二道是帕斯卡三角形二.简单易懂,题目如下: Given an index k, return the kth row of the Pascal's triangle. For ...

  8. 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 [ ...

  9. leetcode—pascal triangle

    1.题目描述 Given numRows, generate the first numRows of Pascal's triangle.   For example, given numRows ...

随机推荐

  1. 自定义view(自定义view的时候,三个构造函数各自的作用)

    package com.timeshare.tmband.Utils; import android.content.Context; import android.content.res.Typed ...

  2. 常用的SQL数据库语句总结

    1as 的用处 as可以对表和列取别名 在开发过程中经常遇到开始给某一个的字段去field1的名称,但后来有感觉field1字段指定不确切,于是又把此字段改成了field2,由于开始认 为field1 ...

  3. linux学习笔记之进程间通信

    一.基础知识. 1:进程通信基础(interProcess Communication, IPC):管道,FIFO(命名管道),XSI IPC,POSIX 信号量. 2:管道. 1,缺陷. 1)部分系 ...

  4. jQuery + css 公告从左往右滚动

    $(function() { // 公告滚动 $(".notice-content").textScroll(); }); /** * 从右往左滚动文字 * @returns {u ...

  5. Github获取仓库最新Release版本号API

    package me.chunsheng.hongbao.utils; import android.content.Context; import android.content.Intent; i ...

  6. shopnc数据库 批量修改商品价格

    1.商品价格统一上调50 2.商品价格个别上调50 UPDATE `nc_goods` SET `goods_price` = `goods_price` +50 where goods_id!=10 ...

  7. openstack安装记录(二)keystone安装

    先决条件 在你配置 OpenStack 身份认证服务前,你必须创建一个数据库和管理员令牌. 完成下面的步骤以创建数据库: 用数据库连接客户端以 root 用户连接到数据库服务器: $ mysql -u ...

  8. NDK 的helloworld步奏

    1. helloworld.c #include <string.h> #include <jni.h> /* * Class: com_example_ndk_NativeH ...

  9. Android中Handle详解

    上图为本人总结的Handler,网上发现一片总结很好的博客就copy过来:作为参考 Handler有何作用?如何使用? 一 .Handler作用和概念 包含线程队列和消息队列,实现异步的消息处理机制, ...

  10. Oracle ORA-01555(快照过旧)

    一.引言: [oracle@yft yft]$ oerr ora 01555 01555, 00000, "snapshot too old: rollback segment number ...