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, ...
随机推荐
- [转]MySQL的简单使用和JDBC示例
MySql简单操作 //启动mysql net start mysql //登陆 mysql -u root -p //创建建数据库 create database mydb; create data ...
- 转: Syslog协议介绍
转: http://liu-hliang.iteye.com/blog/827392 在网上搜的文章,写的很全乎.摘抄如下,供大家参考学习 1.介绍 在Unix类操作系统上,syslog广泛应用于系统 ...
- C#面试:抽象类与接口
本人近日面试遇到此等问题.然后又一次补习了一下下.希望对同行们有所帮助. 一.抽象类: 抽象类是特殊的类,仅仅是不能被实例化:除此以外.具有类的其它特性:重要的是抽象类能够包括抽象方法,这 ...
- ehcache缓存刷新问题
ehcache可以设置时间来定时刷新缓存,但是这个只是清空值,key依旧保存着. 只有你第一次利用key获取值,key才会释放.
- UNP学习笔记(第五章 TCP客户/服务程序实例)
我们将在本章使用前一章中介绍的基本函数编写一个完整的TCP客户/服务器程序实例 这个简单得例子是执行如下步骤的一个回射服务器: TCP回射服务器程序 #include "unp.h" ...
- 【Python数据分析】魔术命令(Magic Command)
IPython有一些特殊的命令(被称为魔术命令),他们有的为常见的任务提供便利,有的则使你能够轻松的控制IPython系统的行为 魔术命令是以百分号%为前缀的命令 常用的IPython魔术命令 命令 ...
- nfs部署和优化 -2
客户端: cat /etc/passwd 显示用户 weifeng 500 服务端: vim /etc/exports /mnt 192.168.1.105(rw,sync,all_squash, ...
- DataTable列 基础处理
DataTable dt=new DataTable(); 新增列: dt.Columns.Add("ColumnsName"); 删除列: dt.Columns.Remove(& ...
- HTML/CSS开发规范指南
参见文档:https://github.com/doyoe/html-css-guide 1.文档目录结构 |-- 项目名 |-- src 开发环境 |-- html 静态页面模板目录 |-- bgi ...
- NGINX下如何自定义404页面
什么是404页面 如果碰巧网站出了问题,或者用户试图访问一个并不存在的页面时,此时服务器会返回代码为404的错误信息,此时对应页面就是404页面.404页面的默认内容和具体的服务器有关.如果后台用的是 ...