杨辉三角,这次要输出第rowIndex行

用滚动数组t进行递推

t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1];

 class Solution {
public:
vector<int> getRow(int rowIndex) {
if(rowIndex < ) return vector<int>(rowIndex + ,);
int n = rowIndex;
vector<int> t[];
for(int i = ; i < ; ++i){
t[i].resize(n + , );
}
for(int i = ; i <= n; ++i){
for(int j = ; j < i; ++j){
t[(i+)%][j] = t[i%][j] + t[i%][j - ];
}
}
return t[(n+) % ];
}
};

Leetcode 119 Pascal's Triangle II 数论递推的更多相关文章

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

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

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

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

  5. leetcode 119 Pascal's Triangle II ----- java

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

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

  7. C#解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  ...

  8. Java for 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 ...

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

随机推荐

  1. C#控件根据窗体改变大小

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  2. linux或者windows下的文件拷贝

    #  上代码 #!/usr/bin/env python # -*- coding:utf-8 -*- import os import shutil import tarfile base_dir ...

  3. POJ 3181 Dollar Dayz DP

    f[i][j]=f[i-j][j]+f[i][j-1],结果很大需要高精度. //#pragma comment(linker, "/STACK:1024000000,1024000000& ...

  4. C# winform 代码生成

    http://www.cnblogs.com/luomingui/archive/2012/09/02/2667217.html 双鱼林: http://www.crsky.com/soft/4941 ...

  5. ssh: connect to host gihub.com port 22: Connection timed out

    方案1(本人使用此方案,问题得已解决): 可能是ssh-server未安装或者未启动.我的ubuntu 12.04 默认只安装了openssh-client,并没有安装server. 运行 ps -e ...

  6. lua 入门学习

    -- 1.Hello world print( "--------------1--------------") print("Hello world"); - ...

  7. monkeyrunner功能函数

    MonkeyRunner Command Summary 1. #导入模块;    from com.android.monkeyrunner import MonkeyRunner, MonkeyD ...

  8. 找出单链表的倒数第K个(从1开始计数)结点的值

    typedef struct Link { int data; struct Link* next; }NODE,*pNODE; NODE *searchK(NODE *phead, int k) { ...

  9. 【堆】【kd-tree】bzoj2626 JZPFAR

    用堆记录答案.看看当前点是否比堆顶更优. #include<cstdio> #include<queue> #include<cstring> #include&l ...

  10. 【转】JavaScript中,{}+{}等于多少?

    原文链接:http://www.2ality.com/2012/01/object-plus-object.html 译文链接:http://www.cnblogs.com/ziyunfei/arch ...