#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. list中的中文转换编码显示

    for i in range(1,sheet.nrows): row=sheet.row_values(i,0,sheet.ncols) row=str(row).replace('u\'','\'' ...

  2. 移动APP项目优化

    团队计划:设计一款给用户提供就医帮助的安卓APP. 项目计划:两个月内团队成员共同开发完成此款APP,此款APP提供预约挂号,名医名院咨询,就医导航等功能. 角色职责:负责交互设计.UI界面设计.1. ...

  3. Mac 快捷键

    总结一下: Ctrl + 关机:弹出关机提示 Ctrl + Opt + 关机 : 正常关机快捷键 Cmd + Opt + 关机 :休眠 Ctrl + Cmd + 关机:重启 Shift + Ctrl ...

  4. Bootstrap 3 Datepicker 使用过程

    最近在创建记录的时候,需要用到日历的功能.本身是使用的bootstrap布局的,所以就找到Datepicker,看了一下用起来还是挺方便的.下面就是使用过程. 依赖的资源 jQuery Moment. ...

  5. sendEmail报错:at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm

    sendEmail发送邮件是出现以下报错: *******************************************************************  Using the ...

  6. .dtsi .dts dtc dtb 是什么

    基础 .dts: device tree source .dtsi:   device tree source include .dts比作源文件,.dtsi比作头文件. dtc是linux源码 /s ...

  7. Mybatis映射文件

    Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同功能的 JDBC 代码进行对比,你会 ...

  8. Rails中的缓存

    最近学习Rails. 看到如下代码: <% if notice %> <p id="notice"><%= notice %></p> ...

  9. 使用rem来开发你的移动端网站

    what is rem ? )css3中的计量元素大小的单位,类似px.pt.em. )一种相对根元素font-size的计算方式.1rem = <html>'s font-size px ...

  10. CSS垂直居中的方法

    前端开发过程中,水平垂直居中是比较常用的.下面直接开门见山,看看不同方法实现垂直居中的各自优点和其不足之处. 1.将“line-height”和“height”设置成一致 这种方法用来实现单行垂直居中 ...