[Algorithm] 118. Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle.
In Pascal's triangle, each number is the sum of the two numbers directly above it.Example:
Input: 5
Output:
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
/**
* @param {number} numRows
* @return {number[][]}
*/
var generate = function(numRows) { if (numRows === ) {
return [];
} let result = []; for (let i = ; i < numRows; i++) {
let row = [];
result.push(row);
for (let j = ; j < i + ; j++) {
if (j === || j === i) {
row.push();
} else {
const temp = result[i-][j-] + result[i-][j];
row.push(temp);
}
}
result[i] = row;
} return result;
};
[Algorithm] 118. Pascal's Triangle的更多相关文章
- 118. Pascal's Triangle
题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...
- Leetcode#118. Pascal's Triangle(杨辉三角)
题目描述 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 5 输出: [ [1], [1,1], [1,2, ...
- LN : leetcode 118 Pascal's Triangle
lc 118 Pascal's Triangle 118 Pascal's Triangle Given numRows, generate the first numRows of Pascal's ...
- 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- ...
- 118. Pascal's Triangle杨辉三角形(全部/一行)
[抄题]: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- [LeetCode]题解(python):118 Pascal's Triangle
题目来源 https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pa ...
- leetcode 118 Pascal's Triangle ----- java
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- Java [Leetcode 118]Pascal's Triangle
题目描述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
随机推荐
- K8S 如何实现将git代码下拉到指定的容器路径中
gitRepo 是 kubernetes Volume类型中的一种,gitRepo volume可以实现将git代码下拉到指定的容器路径中. 备注:实现此功能,Pod运行的节点都必需要安装git.换句 ...
- Spring boot使用influxDB总结
项目中需要存放大量设备日志,且需要对其进行简单的数据分析,信息提取工作. 结合众多考量因素,项目决定使用时序数据库中的领头羊InfluxDB. 引入依赖 项目中使用influxdb-java,在pom ...
- 常用HTTP状态码总结
HTTP状态码(HTTP Status Code) 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求 ...
- 记一次错误排查,主要问题是跨平台文件中换行符(CRLF, LF)和垃圾字符( Caret Notation)
笔者测试SPEC14的workload的时候,需要自定义workload,又需要在Windows和Linux平台上都要测试,所以就遇到了这么个问题:测试工具报错,但是报出来的错误信息又跟错误对不上. ...
- javascript参数化拼接字符串两种方法
javascript如果直接使用字符串+的话,会被大量单引号搞晕,可以有两种比较简单的方法使用参数化拼接. 方式一,传统js //示例:StringFormat("abc{0}def&quo ...
- http响应总结:常见http响应错误总结
工作中经常会被同事问这个http请求为什么调不通,我虽然能解释清楚错误是什么,但是没有总结过,想到刚开始时,也是看了别人的文章才会的,所以总结一下,贡献一下自己的经验. http 404 响应 404 ...
- JS提交表单页面不跳转、JS下载、动态创建from
JS下载 function downloadFile(id) { var url = "<%=request.getContextPath()%>/cer/downlo ...
- 【代码笔记】Web-CSS-CSS组合选择符
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- 完整且易读的最新版小程序登录态和检验注册过没的app.js写法
目录 0.可参考的官方页面 1.流程 2.app.js代码 3.java后台怎么通过code获取openId 0.可参考的官方页面 获取登录凭证:https://developers.weixin.q ...
- Java操作ElasticSearch之创建客户端连接
Java操作ElasticSearch之创建客户端连接 3 发布时间:『 2017-09-11 17:02』 博客类别:elasticsearch 阅读(3157) Java操作ElasticSe ...
