Java for LeetCode 119 Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1]
.
解题思路:
注意,本题的k相当于上题的k+1,其他照搬即可,JAVA实现如下:
public List<Integer> getRow(int rowIndex) {
List<Integer> alist=new ArrayList<Integer>();
rowIndex++;
if(rowIndex<=0)
return alist;
alist.add(1);
for(int i=2;i<=rowIndex;i++){
List<Integer> alist2=new ArrayList<Integer>();
alist2.add(1);
for(int j=1;j<i-1;j++){
alist2.add(alist.get(j-1)+alist.get(j));
}
alist2.add(1);
alist=alist2;
}
return alist;
}
Java for LeetCode 119 Pascal's Triangle II的更多相关文章
- [LeetCode] 119. Pascal's Triangle II 杨辉三角 II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- leetcode 119 Pascal's Triangle II ----- java
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- Java [Leetcode 119]Pascal's Triangle II
题目描述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return ...
- LeetCode 119. Pascal's Triangle II (杨辉三角之二)
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] 119. Pascal's Triangle II 杨辉三角之二
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- C#解leetcode:119. Pascal's Triangle II
题目是: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return ...
- Leetcode 119 Pascal's Triangle II 数论递推
杨辉三角,这次要输出第rowIndex行 用滚动数组t进行递推 t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1]; class Solution { public: ...
- LeetCode OJ 119. Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
随机推荐
- Code signing is required for product type Unit Test Bundle in SDK iOS 8.0
I fixed the issue (temporarily) by going to Edit Scheme, then in the Build section, removing my unit ...
- Redis性能调优建议
一. Redis部署结构优化建议 1. Master不做AOF或RDB持久化,Slave做AOF持久化,建议同时做RDB持久化 2. 所有Master全部增加Slave 3. Master挂载Slav ...
- remove-duplicates-from-sorted-array-ii——去除重复
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- NodeJS待重头收拾旧山河(重拾)
介绍 Node.js®是一个基于Chrome V8 JavaScript引擎构建的JavaScript运行时. Node.js使用事件驱动的非阻塞I / O模型,使其轻便且高效. Node.js的包生 ...
- Python,Pycharm,Anaconda等的关系与安装过程~为初学者跳过各种坑
1.致欢迎词 我将详讲讲述在学Python初期的各种手忙脚乱的问题的解决,通过这些步骤的操作,让你的注意力集中在Python的语法上以及后面利用Python所解决的项目问题上.而我自己作为小白,很不幸 ...
- linux下网卡绑定
网卡绑定的作用:1.冗余,防止单点故障 2.防止传输瓶颈 1.交换机端口绑定: system-view link-aggregation group 1 mode manual 比如把端口1和2进行绑 ...
- 在 CentOS 6.4上安装Erlang
如何在CentOS 6.4上安装erlang,具体的Erlang版本是R15B03-1. 在安装之前,需要先要安装一些其他的软件,否则在安装中间会出现一些由于没有其依赖的软件模块而失败. 一开始,要是 ...
- 在diy的文件系统上创建文件的流程
[0]README 0.1) source code are from orange's implemention of a os , and for complete code , please v ...
- EF6&EFCore 注册/使用实体类的正确姿势
首先回顾下EF中常规使用流程 1.新建实体类以及实体配置(data annotation或fluent api) [Table("Users")] public class Use ...
- 转载 ----Android学习笔记 - 蓝牙篇 (Bluetooth)
1.什么是蓝牙 Bluetooth是目前使用的最广泛的无线通讯协议之一 主要针对短距离设备通讯(10米) 常用于连接耳机.鼠标和移动通讯设备等 2.发现周围蓝牙设备 BluetoothAd ...