#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. 【转载】Tomcat崩溃事件

    转载地址:http://www.blogjava.net/tedeyang/archive/2008/06/04/205740.html Tomcat崩溃事件 今天一大早产品一部项目经理就来找我,他们 ...

  2. xampp修改mysql默认密码详解

    在这里介绍xampp修改mysql默认密码的大概过程是先利用xampp的phpmyadmin进入修改mysql密码,修改之后我们再修改xampp中phpmyadmin的密码,这样就完整的修改mysql ...

  3. Arduino学习经验(一)之解决舵机库和pwm输出冲突

    一.前言 最近在公司学习Arduino uno ,用它实现小车超声波避障功能.实现的功能很简单,就是在小车前方挂一个超声波模块,当碰到障碍物时,会通过舵机进行摆头,判断两边的距离,进行左右转弯.但是碰 ...

  4. placeholder修改字体和颜色

    textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] fo ...

  5. URL中的保留和不安全字符

    书写URL时要使用US-ASCII字符集可以显示的字符. http://www.google.com 如果需要在URL中使用不属于此字符集的字符,就要使用特殊的符号对该字符进行编码. 如:最常使用的空 ...

  6. mariadb:InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes

    mariadb 启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 起因:线上正在运行的系统,因为需要调整性能,变更了my ...

  7. sql-ASCII函数运用

    declare @a int = ASCII('A') declare @b int = ASCII('F') declare @c int = 1 while(@a <= @b) begin ...

  8. python之实现基于paramiko和mysql数据库的堡垒机

    一.堡垒机结构 堡垒机执行流程: 管理员为用户在服务器上创建账号(将公钥放置服务器,或者使用用户名密码) 用户登陆堡垒机,输入堡垒机用户名密码,现实当前用户管理的服务器列表 用户选择服务器,并自动登陆 ...

  9. MyEclipse中的SVN操作手册

    原文出处:http://blog.sina.com.cn/s/blog_8a3d83320100zhmp.html 1.导入项目 点击工具栏上的[File-Import],进入下图 (如果你的对话框中 ...

  10. php : 常用函数

    常用函数: <?php /** * 获取客户端IP * @return [string] [description] */ function getClientIp() { $ip = NULL ...