[LeetCode]119.Pascal#39;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].
Note:
Could you optimize your algorithm to use only O(k) extra space?
思路
无
代码
/**------------------------------------* 日期:2015-02-06* 作者:SJF0115* 题目: 119.Pascal's Triangle II* 网址:https://oj.leetcode.com/problems/pascals-triangle-ii/* 结果:AC* 来源:LeetCode* 博客:---------------------------------------**/#include <iostream>#include <vector>#include <algorithm>using namespace std;class Solution {public:vector<int> getRow(int rowIndex) {vector<int> row(rowIndex+1);vector<int> tmp = row;for (int i = 0;i < rowIndex+1;++i) {tmp[0] = tmp[i] = 1;for (int j = 1;j < i;++j) {tmp[j] = row[j-1] + row[j];}//forrow = tmp;}//forreturn row;}};int main(){Solution s;int n = 0;vector<int> result = s.getRow(n);// 输出for(int i = 0;i < result.size();++i){cout<<result[i]<<" ";}//forcout<<endl;return 0;}
运行时间
[LeetCode]119.Pascal#39;s Triangle II相关推荐
- [leetcode]Pascal#39;s Triangle II
问题叙述性说明: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Re ...
- [LeetCode]--118. Pascal#39;s Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- [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 ...
- LeetCode——Pascal#39;s Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- 【LeetCode从零单排】No118 Pascal#39;s Triangle
题目 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, R ...
- 【LeetCode】剑指 Offer 59 - II. 队列的最大值
[LeetCode]剑指 Offer 59 - II. 队列的最大值 文章目录 [LeetCode]剑指 Offer 59 - II. 队列的最大值 package offer;import java ...
- 【LeetCode】剑指 Offer 58 - II. 左旋转字符串
[LeetCode]剑指 Offer 58 - II. 左旋转字符串 文章目录 [LeetCode]剑指 Offer 58 - II. 左旋转字符串 一.字符串切片 二.列表遍历拼接 三.字符串遍历拼 ...
- 【LeetCode】剑指 Offer 32 - II. 从上到下打印二叉树 II
[LeetCode]剑指 Offer 32 - II. 从上到下打印二叉树 II 文章目录 [LeetCode]剑指 Offer 32 - II. 从上到下打印二叉树 II 一.层序遍历 BFS 一. ...
最新文章
- 【整理】ABAP 7.40新特性介绍(上)
- Python 模块之heapq
- CentOS6安装tomcat6
- usaco-sprime-superprime-pass
- 将sklearn训练速度提升100多倍,美国「返利网」开源sk-dist框架
- sqlparameter多个赋值一行完成_HashMap源码从面试题说起:请一行一行代码描述hashmap put方法...
- python字符串find方法(二分钟读懂)
- 数据分析能力的8个等级,你能做到哪一步?
- font-family字体-常用字体中英文对照表
- dell电脑恢复出厂系统(旧电脑如何重装系统)
- Macbook二三事
- 行内元素之间产生的间隙
- Vue多个元素的过渡
- 赴日本常见问题QA (2转 不明原处)
- 【代码实践】使用CLIP做一些多模态的事情
- 2022茶艺师(初级)操作证考试题库及在线模拟考试
- mysql 难点_数据库技术的重点与难点有什么?
- AP计算机从懵懵懂懂到突飞猛进-----加利福尼亚学生满分经验分享!
- Java分别使用zxing及qrcode-plugin生成各种样式二维码
- linux 防火墙 功能点,功能点(Funciton Point FP)估算法(三) 调整因子