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,3,1]
.
Note:
Could you optimize your algorithm to use only O(k) extra space?
class Solution { public:vector<int> getRow(int rowIndex) {vector<int> a(rowIndex + 1);a[0] = 1;for(int i = 1; i <= rowIndex; i++) //遍历行for(int j = i; j >= 0; j--) //遍历行中的元素,第k行有k个元素。注意行中元素需要从右往左遍历,否则下一行填写的结果会覆盖上一行还未使用的元素if (j == i)a[j] = a[j-1];else if (j == 0)a[j] = a[j];elsea[j] = a[j-1] + a[j];return a; } };
转载于:https://www.cnblogs.com/qionglouyuyu/p/4854608.html
119. Pascal's Triangle II (Graph; WFS)相关推荐
- [LeetCode]119.Pascal's Triangle II
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/SunnyYoona/article/details/43562603 题目 Given an ind ...
- LeetCode 119. Pascal’s Triangle II
119. Pascal's Triangle II My Submissions QuestionEditorial Solution Total Accepted: 72147 Total Subm ...
- Leet Code OJ 119. Pascal's Triangle II [Difficulty: Easy]
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return ...
- LeetCode - Easy - 119. Pascal‘s Triangle II
Topic Array Description https://leetcode.com/problems/pascals-triangle-ii/ Given an integer rowIndex ...
- leetcode python3 简单题119. Pascal's Triangle II
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十九题 (1)题目 英文: Given a non-negative ind ...
- 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 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 ...
- [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 ...
- 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 ...
最新文章
- 如何在CPU上优化GEMM矩阵乘法
- python基础 继承
- python的编译器有哪些-python的编译器有哪些
- 对信号集操作函数的使用方法和顺序
- flink 1-个人理解
- win7,ubuntu双系统——重装win7后如何恢复ubuntu引导
- 文件上传函数(get post assert)
- JS和Jquery获取和修改label的值
- java 多个timer_java – Timer正在创建多个计时器实例
- getnumdevices.c setgetdevicetype例程
- ubuntu14.04 搭建 tftp 服务器
- 如何在CAD中利用块实现坐标、高程的自动标注
- window.opener 与 window.dialogArguments的用法
- cad画流程图的插件_PIDCAD工艺流程图绘图软件
- GIT提交代码到远程创库
- python程序设计的选择题_智慧树Python程序设计基础选择题答案
- 美赞臣中国独立后任命朱定平为总裁;思拓凡亚洲首个技术研发卓越中心上海揭幕 | 美通社头条...
- 腾讯、字节、蘑菇街、阿里实习生面经(面试记录)(2)
- aria2 txt导入_aria2 让下载提速
- 电蚊拍 电路图 原理
热门文章
- Akka Cluster原理与应用
- C#调用dll提示试图加载格式不正确的程序解决方法
- C#.Net网页加载等待效果漂亮并且简单
- python全栈学习--day40()
- 服务器出现 nginx 502 Bad Gateway
- 河南省第七届省赛 问题 F: Turing equation 水题
- 几句话描述简单算法——排序与搜索
- Unity学习笔记 - Assets, Objects and Serialization
- 15.用PHP写出显示客户端IP与服务器IP的代码,如何防止用户使用代理的情况?[添加更多详情]...
- C# 文件保存到数据库中或者从数据库中读取文件