Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3,
Return [1,3,3,1].

Note:
Could you optimize your algorithm to use only O(k) extra space?

因为需要O(k)的空间,因此需要对同一个数组进行重写,可以从后往前进行覆盖,则没有问题

需要注意的一个问题是 Arrays.asList()操作的不能使基本类型数组

 1 public class Solution {
 2     public List<Integer> getRow(int rowIndex) {
 3         Integer [] row = new Integer[rowIndex+1];
 4         row[0]=1;
 5         if(rowIndex==0)return Arrays.asList(row);
 6         row[1]=1;
 7         if(rowIndex==1) return Arrays.asList(row);
 8         for(int i = 2; i<=rowIndex;i++){
 9             row[i]=1;
10             for(int j=i-1;j>=1;j--){
11                 row[j]=row[j]+row[j-1];
12             }
13         }
14         return Arrays.asList(row);
15     }
16 }

转载于:https://www.cnblogs.com/deepblueme/p/4736091.html

[Leetcode] Pascal's Triangle II相关推荐

  1. LeetCode 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 ...

  2. Leetcode: 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. [LeetCode]119.Pascal's Triangle II

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/SunnyYoona/article/details/43562603 题目 Given an ind ...

  4. LeetCode 119. Pascal’s Triangle II

    119. Pascal's Triangle II My Submissions QuestionEditorial Solution Total Accepted: 72147 Total Subm ...

  5. LeetCode - Easy - 119. Pascal‘s Triangle II

    Topic Array Description https://leetcode.com/problems/pascals-triangle-ii/ Given an integer rowIndex ...

  6. leetcode python3 简单题119. Pascal's Triangle II

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十九题 (1)题目 英文: Given a non-negative ind ...

  7. C#LeetCode刷题之#119-杨辉三角 II(Pascal‘s Triangle II)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3690 访问. 给定一个非负索引 k,其中 k ≤ 33,返回杨辉 ...

  8. LeetCode Pascal's Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  9. 119. Pascal's Triangle II (Graph; WFS)

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  10. [Array]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 ...

最新文章

  1. 51单片机怎么学啊?有推荐的网课和书籍么?
  2. excel如何分类汇总_Excel教程:一个排序后分类汇总他弄了一天 Excel神技能!
  3. 解决ubuntu打开windows中txt文件出现乱码现象
  4. 使用NFS 实现两台服务器间的数据备份. -- NFS 设置部分.
  5. 【9018:1956】线段树1
  6. offsetTop、offsetLeft、offsetWidth、offsetHeight、style中的样式
  7. SUSE11 搭建iscsi target 配置
  8. 看过这五条,再离职!
  9. 1.9 编程基础之顺序查找 01 查找特定的值 python AC
  10. linux下编程输入密码不回显
  11. linux su,sudo命令
  12. java皮卡丘代码_Picachu代码源代码,皮卡丘,源码
  13. noip2013 day1
  14. Git廖雪峰 常用命令总结
  15. [笔记分享] [Camera] 相机的flash led功能小结
  16. 飞鸽传书2007绿色版还需要遵循些基本的原则
  17. html编辑器的回车换行问题解决方案
  18. R语言基础-Rstudio基本使用
  19. VUE—下载安装并使用mint ui(图文详情)
  20. java+ElementUI前后端分离旅游项目第七天 权限管理和图形报表

热门文章

  1. 什么是共享读锁和排他写锁?
  2. 作业4 猜数字游戏jsp
  3. IE 8 Beta 2中文版首份试用体验
  4. ASP.NET 2.0的编译行为
  5. Webbench学习笔记一:源码获取和使用
  6. 斜率优化dp学习笔记
  7. Linux下汇编语言学习笔记76 ---
  8. 2017-02-26,周日整理
  9. java笔记--查看和修改线程名称
  10. [转载]窗口之间的主从关系与Z-Order