题目

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相关推荐

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

  2. [LeetCode]--118. Pascal#39;s Triangle

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

  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——Pascal#39;s Triangle

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

  6. 【LeetCode从零单排】No118 Pascal#39;s Triangle

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

  7. 【LeetCode】剑指 Offer 59 - II. 队列的最大值

    [LeetCode]剑指 Offer 59 - II. 队列的最大值 文章目录 [LeetCode]剑指 Offer 59 - II. 队列的最大值 package offer;import java ...

  8. 【LeetCode】剑指 Offer 58 - II. 左旋转字符串

    [LeetCode]剑指 Offer 58 - II. 左旋转字符串 文章目录 [LeetCode]剑指 Offer 58 - II. 左旋转字符串 一.字符串切片 二.列表遍历拼接 三.字符串遍历拼 ...

  9. 【LeetCode】剑指 Offer 32 - II. 从上到下打印二叉树 II

    [LeetCode]剑指 Offer 32 - II. 从上到下打印二叉树 II 文章目录 [LeetCode]剑指 Offer 32 - II. 从上到下打印二叉树 II 一.层序遍历 BFS 一. ...

最新文章

  1. 【整理】ABAP 7.40新特性介绍(上)
  2. Python 模块之heapq
  3. CentOS6安装tomcat6
  4. usaco-sprime-superprime-pass
  5. 将sklearn训练速度提升100多倍,美国「返利网」开源sk-dist框架
  6. sqlparameter多个赋值一行完成_HashMap源码从面试题说起:请一行一行代码描述hashmap put方法...
  7. python字符串find方法(二分钟读懂)
  8. 数据分析能力的8个等级,你能做到哪一步?
  9. font-family字体-常用字体中英文对照表
  10. dell电脑恢复出厂系统(旧电脑如何重装系统)
  11. Macbook二三事
  12. 行内元素之间产生的间隙
  13. Vue多个元素的过渡
  14. 赴日本常见问题QA (2转 不明原处)
  15. 【代码实践】使用CLIP做一些多模态的事情
  16. 2022茶艺师(初级)操作证考试题库及在线模拟考试
  17. mysql 难点_数据库技术的重点与难点有什么?
  18. AP计算机从懵懵懂懂到突飞猛进-----加利福尼亚学生满分经验分享!
  19. Java分别使用zxing及qrcode-plugin生成各种样式二维码
  20. linux 防火墙 功能点,功能点(Funciton Point FP)估算法(三) 调整因子

热门文章

  1. Javascript在页面加载时的执行顺序(转载)
  2. 初学Vue.js,从头来过~
  3. 如何用Markdown轻松排版知乎专栏文章?
  4. Arithmetic Slices
  5. Python 日期格式相关
  6. 如何制作自己的静态库
  7. 在Extjs中动态增加控件
  8. 4-3逻辑非运算符及案例 4-4
  9. angularjs中使用swiper时不起作用,最后出现空白位
  10. FPGA浮点数定点化