118. Pascal's Triangle
2016-06-08 11:38
267 查看
题目:https://leetcode.com/problems/pascals-triangle/
代码:
代码:
public class Solution { public List<List<Integer>> generate(int numRows) { List<List<Integer>> res = new ArrayList<>(); ArrayList t1 = new ArrayList<>(); ArrayList t2 = new ArrayList<>(); t1.add(1); t2.add(1);t2.add(1); if(numRows==0) return res; res.add(t1); if(numRows==1) { return res; } res.add(t2); if(numRows==2) { return res; } for(int i=2;i<numRows;i++) { ArrayList<Integer> temp = new ArrayList<>(); temp.add(1); for(int j=1;j<=i-1;j++) { temp.add(res.get(i-1).get(j-1)+res.get(i-1).get(j)); } temp.add(1); res.add(temp); } return res; } } 1ms
相关文章推荐
- label 显示不同颜色 不同文字点击事件
- UVa 11360 - Have Fun with Matrices
- centOS6搭建lnmp环境
- Collections sort 实体类排序
- 2.URL
- centOS6搭建lnmp环境
- iOS中iconfont(图标字体)的基本使用
- Socket简介
- Linux网络流量监控与分析工具Ntopng
- Python爬虫实战(2):爬取京东商品列表
- 26. Remove Duplicates from Sorted Array
- React + Redux
- 怎么用EDIUS将静帧图片做出动态特效
- Android之SurfaceView学习(一)
- oracle ORA-28000: the account is locked
- Linux Shell系列教程之(八)Shell printf命令详解
- C#开发奇技淫巧三:把dll放在不同的目录让你的程序更整洁
- Linux 设备驱动--- 内核等待队列
- JAVA中批量插入数据
- 带您认识不一样的Cognos