Pascal's Triangle
2015-09-24 22:32
211 查看
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]
]
int** generate(int numRows, int** columnSizes, int* returnSize) {
}
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
int** generate(int numRows, int** columnSizes, int* returnSize) {
*returnSize = numRows; int** returnNums = (int**)malloc(sizeof(int*)*(*returnSize)); *columnSizes = (int*)malloc(sizeof(int)*(*returnSize)); for (int i = 0; i < *returnSize; i++) { returnNums[i] = (int*)malloc(sizeof(int)*(i+1)); (*columnSizes)[i] = i+1; } for (int i = 0; i < *returnSize; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) { returnNums[i][j] = 1; } else { returnNums[i][j] = returnNums[i-1][j-1] + returnNums[i-1][j]; } } } return returnNums;
}
相关文章推荐
- mongodb 数据库操作--备份 还原 导出 导入
- 经典算法题每日演练——第五题 字符串相似度
- netstat命令
- 线段树模板(poj3468)
- Java多线程基础知识(四)
- C语言的第不知道多少天
- Java覆盖和隐藏
- Tomcat7基于Redis的Session共享
- Linux文件操作与IO函数
- 顶部滑动下拉广告
- 安卓小结《1》
- 中国省、市、区的Json数据
- 高效缓存服务器Memcached(二)
- 关系型数据库理论
- Josephus问题分析与实现
- unwrapped与wrapped变量取值的问题
- ecshop二次开发 使用ecshop电子商务系统的100个小问题
- HDU 3849--By Recognizing These Guys, We Find Social Networks Useful【边双联通 && 求桥的数目 && 输出桥】
- STL系列之三 queue 单向队列
- 音频播放 - 音效