#include <stdio.h>
int** generate(int numRows, int** columnSizes) {
if (numRows == 0) {
columnSizes = NULL;
return NULL;
}
int** res = NULL;
res= (int **) malloc (numRows*sizeof(int *));
(*columnSizes) = (int *) malloc(numRows*sizeof(int));
int i,j;
for (i = 0; i< numRows; i++) {
res[i] = (int*) malloc((i+1)*sizeof(int));
(*columnSizes)[i] = i+1;
if (0==i) {
res[i][0] = 1;
}
else {
res[i][0] = 1;
res[i][i] = 1;
if (i > 1) {
for (j =1; j<i;j++) {
res[i][j] = res[i-1][j-1]+ res[i-1][j];
}
}
}
}
return res;
}
int main (int argc, char * argv[]) {
int *Size = NULL;
int **res = generate(5, &Size);
if (Size != NULL && res != NULL) {
int i,j;
for (i =0; i<5; i++) {
for (j = 0; j< Size[i];j++) {
fprintf(stdout,"%d \n",res[i][j]);
}
fprintf(stdout,"\n");
}
for (i = 0; i < 5;i++) {
if (res[i] != NULL) {
free(res[i]);
res[i]=NULL;
}
}
free(res);
res = NULL;
if (Size != NULL) {
free(Size);
Size = NULL;
}
}
return 0;
}

leetcode Pascal's triangle的更多相关文章

  1. LeetCode:Pascal's Triangle I II

    LeetCode:Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For examp ...

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

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

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

  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 @ Python

    原题地址:https://oj.leetcode.com/problems/pascals-triangle-ii/ 题意: Given an index k, return the kth row ...

  6. [leetcode]Pascal's Triangle @ Python

    原题地址:https://oj.leetcode.com/problems/pascals-triangle/ 题意: Given numRows, generate the first numRow ...

  7. 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题4

    当我们需要改变数组的值时,如果从前往后遍历,有时会带来很多麻烦,比如需要插入值,导致数组平移,或者新的值覆盖了旧有的值,但旧有的值依然需要被使用.这种情况下,有时仅仅改变一下数组的遍历方向,就会避免这 ...

  8. LeetCode - Pascal's Triangle II

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

  9. LeetCode: Pascal's Triangle II 解题报告

    Pascal's Triangle II Total Accepted: 19384 Total Submissions: 63446 My Submissions Question Solution ...

  10. LeetCode: Pascal's Triangle 解题报告

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

随机推荐

  1. ASP。net 之view

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs&qu ...

  2. HTML空格标签

    双学位论文+本学位开题报告+实训项目+实训考试+学员考试,真是脑子都要爆炸... 话不多说,留个小知识点,HTML的空格替代符号表示法: 1. 半个空白,1个字符宽度:  或者   2.1个空白,2个 ...

  3. 【HDU2255】奔小康赚大钱-KM算法

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description ...

  4. Mybatis-Spring集成

    MyBatis-Spring用来将MyBatis无缝整合到Spring中.使用这个类库中的类, Spring将会加载必要的MyBatis工厂类和Session类. 这个类库也提供一个简单的方式来注入 ...

  5. Unity手撸2048小游戏——背景文字控制

    今天继续昨天的计划吧 1.新建项目.场景命名啥的都不说了吧. 2.直接开始新建一个Image,顺便把Image改名成Chessman 3.选中Image新建一个Text对象,调整下大小位置.这样就算完 ...

  6. 读《编写可维护的JavaScript》第二三章总结

    第二章 注释 添加注释的一般原则是,在需要让代码变得清晰时添加注释. 2.1 ① 单行注释 独占一行的注释,用来解释下一行代码.这行注释之前总是有一个空行,且缩进层级和下一行代码保持一致. 在代码行的 ...

  7. 软件工程(C编码实践篇)总结

    陆伟丹 + 原创作品转载请注明出处 + <软件工程(C编码实践篇)>MOOC课程http://mooc.study.163.com/course/USTC-1000002006 对软件工程 ...

  8. miniprofiler对方法的时间性能检测

    miniprofiler对方法的时间性能检测 直接上代码 using StackExchange.Profiling; ... var profiler = MiniProfiler.Current; ...

  9. [python]python中,使用traceback处理异常信息

    近来编写一个程序,该程序可以在设定时间内,获取指定文件夹更新的文件夹和文件列表,并根据获取到的更新列表,做一些操作.由于所写程序是放在服务器上运行,为了保证程序在运行的过程中,不时不时跳出些异常信息出 ...

  10. img的绝对路径转为相对路径

    $('#add_img').on('change', function(){ var objUrl = getObjectURL(this.files[0]) ; if (objUrl) { $(th ...