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) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<vector<int>> result;
if(numRows <= ) return result; vector<int> first;
first.push_back(); result.push_back(first); for(int i = ; i < numRows ; i++)
{
vector<int> temp(i+);
for(int j = ; j < i+ ; j++){
if( j == || j == i){
temp[j] = ;continue;
}else{
temp[j] = result[i-][j] + result[i-][j-] ;
continue;
}
}
result.push_back(temp);
} return result ;
}
};

LeetCode_Pascal's Triangle的更多相关文章

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

  2. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  3. [LeetCode] 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, ...

  4. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  5. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  6. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  7. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  8. Triangle - Delaunay Triangulator

    Triangle - Delaunay Triangulator  eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...

  9. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

随机推荐

  1. 这样就算会了PHP么?-5

    汇集一点关于数据深入一些的几个函数,去重,弹出,加入,查找.... <?php $str = "时装,休闲,职业装"; $strs = explode(",&quo ...

  2. JAVA在线基础教程!

    http://www.runoob.com/java/java-tutorial.html http://www.51zxw.net/list.aspx?cid=380 http://www.weix ...

  3. fstream读写UNICODE文件

    今天遇到要处理UNICODE文件的情况,网上找了一圈都是读取出字节,再转的,这个不方便啊!想起了有codecvt这么个东西,顺藤摸瓜,找到了方法. locale utf16(locale(" ...

  4. poj 1486 Sorting Slides(二分图匹配的查找应用)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  5. html5标签收集

    <meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0& ...

  6. pyqt学习之列表管理器(网友提供)

    # -*- coding: utf-8 -*- __author__ = 'Administrator' import sys from PyQt4.QtCore import * from PyQt ...

  7. px 和 em换算

    常用px,pt,em换算表 pt (point,磅):是一个物理长度单位,指的是72分之一英寸. px (pixel,像素):是一个虚拟长度单位,是计算机系统的数字化图像长度单位,如果px要换算成物理 ...

  8. openwrt上网配置的一些理解

    其实已经有很多帖子讲过openwrt路由器上网配置了,我这里主要是讲我自己的一块硬件路由使用openwrt后的一些上网配置.之所以要研究我自己的配置,是因为硬件,硬件不一样,配置也就不一样,但是总的原 ...

  9. 应用highcharts做直观数据统计

    最近在看上了统计类的东东,发现以前端图表神器:highcharts Highcharts是一款功能强大.开源.美观.图表丰富.兼容绝大多数浏览器的纯Js图表库,Highcharts支持的图表类型有直线 ...

  10. C#上传图片同时生成缩略图,控制图片上传大小。

    #region 上传图片生成缩略图 /// <summary> /// 上传图片 /// </summary> /// <param name="sender& ...