LeetCode(33)-Pascal's Triangle II
来源:互联网 发布:数据归一化后的值 编辑:程序博客网 时间:2024/06/01 18:44
题目:
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].
思路:
- 要求是返回帕斯卡某一行的数据
- 设置两个list变量,pre和next,pre用来存储当前的最后的最后一行,next存储下一行,next赋值给pre(在这之前pre清空,之后next清空),往下移动 -
代码:
public class Solution { public List<Integer> getRow(int rowIndex) { List<Integer> pre = new ArrayList<Integer>(); List<Integer> next = new ArrayList<Integer>(); pre.add(1); if(rowIndex == 0){ return pre; } for(int i = 1;i < rowIndex+1;i++){ next.add(1); for(int a = 1;a < i;a++){ next.add(pre.get(a-1)+pre.get(a)); } next.add(1); pre.clear(); for(int o =0;o < next.size();o++ ){ pre.add(next.get(o)); } next.clear(); } return pre; }}
0 0
- LeetCode 33 Pascal's Triangle II
- LeetCode(33)-Pascal's Triangle II
- LeetCode Pascal's Triangle II
- LeetCode: Pascal's Triangle II
- [LeetCode] Pascal's Triangle II
- [Leetcode] Pascal's Triangle II
- 【leetcode】Pascal's Triangle II
- LeetCode - Pascal's Triangle II
- Leetcode: Pascal's Triangle II
- LeetCode-Pascal's Triangle II
- [leetcode] Pascal's Triangle II
- LeetCode - Pascal's Triangle II
- LeetCode | Pascal's Triangle II
- Pascal's Triangle II -leetcode
- Leetcode Pascal's Triangle II
- [LeetCode] Pascal's Triangle II
- Leetcode: Pascal's Triangle II
- Leetcode Pascal's Triangle II
- API 平台
- 树形dp-hdu1520
- 解决gradle project sync failed.Basic functionality(e.g.editing,debugging) will not work properly
- java单例设计模式
- 《ZooKeeper》 Chapter 3 Getting Started with the ZooKeeper API
- LeetCode(33)-Pascal's Triangle II
- java日期处理类
- POJ1659 Frogs' Neighborhood
- spark单机部署问题
- XML简介
- Github入门教程
- 利用随机数函数生成 6 个字符,依次拼接到“Words:”字符串的末尾, 并输出该字符串的长度,大写英文字母的个数。
- 窗口的子类化与超类化
- 快速排序