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 [1,3,3,1]
.
解题思路:
每次在上一个list前面插入1,然后后面的每两个间相加赋值给前一个数。
代码描述:
public class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> result = new ArrayList<Integer>();
for(int i = 0; i <= rowIndex; i++){
result.add(0,1);
for(int j = 1; j < i; j++){
result.set(j, result.get(j) + result.get(j + 1));
}
}
return result;
}
}
Java [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, ...
- 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 ...
- 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, ...
- 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, ...
随机推荐
- 【转】KM匹配题集
转自:http://blog.csdn.net/shahdza/article/details/7779324 [HDU]2255 奔小康赚大钱 模板题★1533 Going Home 模板题★242 ...
- error X3025:global variables are implicitly constant, enable compatibility mode to allow modification
global variables are implicitly constant, enable compatibility mode to allow modification http://xbo ...
- 高性能网络编程2----TCP消息的发送
转 陶辉 taohui.org.cn 在上一篇中,我们已经建立好的TCP连接,对应着操作系统分配的1个套接字.操作TCP协议发送数据时,面对的是数据流.通常调用诸如send或者write方法来发送数据 ...
- cf 363A B C
A水题 ~~ 注意0输出 /************************************************************************* > Author ...
- kill 非法用户
主要涉及到的相关命令如:who/w/ps/kill/pkill/killall查看当前登录用户:[root@localhost ~]# whoroot pts/1 2010-08 ...
- HDU 1540 / POJ 2892 Tunnel Warfare (单点更新,区间合并,求包含某点的最大连续个数)
题意:一条线上有n个点,D x是破坏这个点,Q x是表示查询x所在的最长的连续的点的个数,R是恢复上一次破坏的点. 思路:这题的关键是查询. 将被毁的村庄看成空位,当查询某个点的时候,如果我们知道它左 ...
- Matlab安装
第一步:下载MATLAB 7.0,下载自己百度下就好. 三个ios文件 第二步:把每个IOS文件直接右键解压就好. 第三步:打开第一个解压文件夹.双击.exe文件 第四步:next之后把序列号黏贴上去 ...
- JsRender系列demo(7)compline
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.j ...
- **CI两种方式查询所返回的结果数量
区别:第一个是有条件的:第二个没有条件 $this->db->count_all_results(); 允许你获得某个特定的Active Record查询所返回的结果数量.可以使用Acti ...
- Bessie的体重问题
P1028 Bessie的体重问题 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 USACO OCT09 8TH 描述 Bessie像她的诸多姊妹一样,因 ...