博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leetcode: Pascal's Triangle
阅读量:4665 次
发布时间:2019-06-09

本文共 716 字,大约阅读时间需要 2 分钟。

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]]

 

1 public class Solution { 2     public ArrayList
> generate(int numRows) { 3 ArrayList
> result = new ArrayList
>(); 4 List
item; 5 if (numRows <= 0) return result; 6 for (int i=0; i
(); 8 for (int j=0; j<=i; j++) { 9 if (j==0 || j==i) item.add(1);10 else {11 List
prev = result.get(i-1);12 item.add(prev.get(j-1) + prev.get(j));13 }14 }15 result.add(new ArrayList
(item));16 }17 return result;18 }19 }

 

转载于:https://www.cnblogs.com/EdwardLiu/p/3756296.html

你可能感兴趣的文章
Spring框架:Spring容器具体解释
查看>>
一个完美的世界 访问
查看>>
【PLSQL】package包的使用
查看>>
可持久化数据结构
查看>>
solr 4.4添加索引是新手容易遇到的问题
查看>>
JavaScript的跨域共享的方法
查看>>
(网页)jQuery的时间datetime控件在AngularJs中使用实例
查看>>
利用Android-FingerprintManager类实现指纹识别
查看>>
flask---注册-验证简单逻辑api接口
查看>>
[Python] Create a minimal website in Python using the Flask Microframework
查看>>
【PHP 】 伪静态 - 3. 伪静态的基本使用
查看>>
LA 4636 (贪心) Cubist Artwok
查看>>
项目经理怎样获得领导和客户的认可
查看>>
多线程优化 锁升级
查看>>
Linux文件系统
查看>>
安卓APP测试验证点总结
查看>>
idea启动崩溃问题
查看>>
python3 异常处理
查看>>
hdu2102(广搜)
查看>>
java.security.NoSuchAlgorithmException: SHA1PRNG SecureRandom not available
查看>>