1 Star 0 Fork 0

表情扭曲 / leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc118.java 919 Bytes
一键复制 编辑 原始数据 按行查看 历史
liu13 提交于 2019-01-30 22:55 . 20190130
package code;
/*
* 118. Pascal's Triangle
* 题意:上层元素相邻的和,两边补1,得到下层元素
* 难度:Easy
* 分类:Array
* 思路:迭代计算
* Tips:
*/
import java.util.ArrayList;
import java.util.List;
public class lc118 {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> res = new ArrayList<>();
if(numRows==0) return res;
List<Integer> ls = new ArrayList();
ls.add(1); //第一层1个1
res.add(ls);
numRows--;
if(numRows==0) return res;
while(numRows>0){
ArrayList<Integer> temp = new ArrayList();
temp.add(1);
for (int i = 0; i < ls.size()-1 ; i++) {
temp.add(ls.get(i)+ls.get(i+1));
}
temp.add(1);
res.add(temp);
ls = temp;
numRows--;
}
return res;
}
}
1
https://gitee.com/abfantasy/leetcode.git
git@gitee.com:abfantasy/leetcode.git
abfantasy
leetcode
leetcode
master

搜索帮助