LeetCode——Pascal's Triangle II
2015-06-19 21:53
441 查看
Description:
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3, Return
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3, Return
[1,3,3,1].
public class Solution { public List<Integer> getRow(int rowIndex) { List<List<Integer>> list = new ArrayList<List<Integer>>(); for(int i=0; i<=rowIndex; i++) { List<Integer> tList = new ArrayList<Integer>(); if(i == 0) { tList.add(1); } else { for(int j=0; j<=i; j++) { if(j == 0 || j == i) { tList.add(1); } else { tList.add(list.get(i-1).get(j) + list.get(i-1).get(j-1)); } } } list.add(tList); } return list.get(rowIndex); } }
相关文章推荐
- Nginx HA 及https配置部署
- Android dpi、dip、px、分辨率、屏幕尺寸、density 关系以及换算
- Elevator
- 由二叉树的先序中序推出后序
- 【剑指offer 面试题12】打印1到最大的n位数
- 属性动画
- Elevator 分类: HDU 2015-06-19 21:52 13人阅读 评论(0) 收藏
- cocos2d-x-3.6最新基础
- iOS开发笔记21--layoutSubviews总结
- SDP在SIP协议中的应用
- 轻量级
- Tutorial 5: Uniform Variables
- 2015061902 - 影响
- 2015061903 - 浏览器市场份额
- Nginx 配置详解
- strlen()函数
- C语言一个栈的实现
- 根据前序和后序求出中序
- 《人,绩效和职业道德》及博客的读后感
- 感想