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, ...
随机推荐
- 【iOS】Frame和Bounds的区别以及获取绝对坐标的办法
终于搞清楚了,UIView中的frame获取的是相对于所在ParentView的坐标,而bounds则是指UIView本身的坐标.比如下图(假设A是屏幕): View B的Frame坐标是指相对于Vi ...
- 13.【nuxt起步】-部署到正式环境
已经购买centos服务器,并安装了nodejs环境 Secure CRT链接 Cd / Cd /var/www Mkdir test.abc.cn 用ftp 除了node_modules,其他都上传 ...
- ylb:SQL 索引(Index)
ylbtech-SQL Server: SQL Server-SQL 索引(Index) SQL 索引(Index). ylb:索引(Index) 返回顶部 --=================== ...
- 七天学会ASP.NET MVC (二)——ASP.NET MVC 数据传递 【转】
http://www.cnblogs.com/powertoolsteam/p/MVC_two.html 通过第一天的学习之后,我们相信您已经对MVC有一些基本了解. 本节所讲的内容是在上节的基础之上 ...
- Batch update returned unexpected row count from update [0];
Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested ...
- 4种使用webpack提升vue应用的方式
本文参考自:https://mp.weixin.qq.com/s?src=11×tamp=1526886111&ver=889&signature=u9SixhvlJ ...
- shell循环,判断介绍,以及实例
shell的循环主要有3种,for,while,until shell的分支判断主要有2种,if,case 一,for循环 #!/bin/bash for file in $(ls /tmp/test ...
- DeepinXP Lite 6.2 精简版220M 安装IIS
本作品由Man_华创作,采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.基于http://www.cnblogs.com/manhua/上的作品创作. 用虚拟机装了DEEP ...
- oracle session和process的关系
什么是session 通俗来讲,session 是通信双方从开始通信到通信结束期间的一个上下文(context).这个上下文是一段位于服务器端的内存:记录了本次连接的客户端机器.通过哪个应用程序.哪个 ...
- eeplat开发平台概念理解
近期在学习eeplat的开发.发现其中有非常多概念实在让人easy忘记,所以谨以此文记录一笔. eeplat的开发文档里说eeplat是元数据驱动的,这个元数据什么意思.在我理解就是后台的数据库里面的 ...