三角相对简答题。第一个问题是太简单。我不沾了,我一定会写。其实没什么的第二个问题,与这个问题计算路径有点像一个三角形,假定输入是n,然后从第一行计数到第一n行,保存在数据线上的时间到,由于只有相关的事情跟上一行,为了防止覆盖,计数从前进或后退。

直接附着到代码:

class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res(rowIndex+1) ;
if(rowIndex < 0)
return res;
res[0] = 1;
for(int i=1;i<=rowIndex;i++){
res[i] = 1;
for(int j=i-1;j>0;j--){
res[j] = res[j-1]+res[j];
}
}
return res;
}
};

版权声明:本文博客原创文章,博客,未经同意,不得转载。

leetcode先刷_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, Return [1,3 ...

  2. LeetCode OJ 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, ...

  3. 【一天一道LeetCode】#119. Pascal's Triangle II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  4. LeetCode——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 ...

  5. [LeetCode]Pascal&#39;s Triangle II

    题目:给定一个行索引index,返回帕斯卡三角形第index层的三角形 算法:生成index层帕斯卡三角形,并返回第index层三角形 public class Solution { public L ...

  6. 【LeetCode OJ】Pascal's Triangle II

    Problem Link: http://oj.leetcode.com/problems/pascals-triangle-ii/ Let T[i][j] be the j-th element o ...

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

  8. 【LeetCode】119. Pascal's Triangle II

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

  9. LeetCode算法题-Pascal's Triangle II(Java实现)

    这是悦乐书的第171次更新,第173篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第30题(顺位题号是119).给定非负索引k,其中k≤33,返回Pascal三角形的第k ...

随机推荐

  1. Your algorithm's runtime complexity must be in the order of O(log n).

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  2. css3-11 如何改变背景图片的大小和位置

    css3-11 如何改变背景图片的大小和位置 一.总结 一句话总结:css3相对css2本身就支持改变背景图片的大小和位置. 1.怎么设置背景不填充padding部分? background-orig ...

  3. php 随机数中奖demo演示

    感谢https://blog.csdn.net/z960339491/article/details/69511491提供的思路,应该是java,于我不合适,写了php <?php // 中奖概 ...

  4. 关于JavaScript概念的总结

    原文 https://www.jianshu.com/p/1e8d8a691aa8 大纲 1.JavaScript的概念 2.JavaScript 特点 3.JavaScript是弱类型语言 4.Ja ...

  5. Windows Phone 8.1 Tiles, Notifications and Action Center

    (1)Tiles Tiles 也就是磁贴,是 Windows Phone 的一大特色. 一个 Tile 其实可以看成是一个 XML,比如: <tile> <visual> &l ...

  6. com.octo.captcha.service.CaptchaServiceException: Invalid ID, could not validate unexisting o

    <p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px;"& ...

  7. QT学习记录之理解信号槽机制

    作者:朱金灿 来源:http://blog.csdn.net/clever101 QT的事件机制采用的信号槽机制.所谓信号槽机制,简而言之就是将信号和信号处理函数绑定在一起,比如一个按钮被单击是一个信 ...

  8. HTML代码简写法:Emmet和Haml(转)

    HTML代码写起来很费事,因为它的标签多. 一种解决方法是采用模板, 在别人写好的骨架内,填入自己的内容.还有一种就是我今天想要介绍的方法----简写法. 常用的简写法,目前主要是Emmet和Haml ...

  9. JAVA类(下)

    我看完了Java类,与C++相比,复杂了一点.其中有类的嵌套定义即内部类,枚举类等. 我看这两节花了我很多时间.其中有一些概念还是有点难懂. 下面,我详细总结内部类与枚举类. 内部类 内部类的主要作用 ...

  10. 对多线程java内存模型JMM

    多线程概念的引入体现了人类重新有效压力寨计算机.这是非常有必要的,由于所涉及的读数据的过程中的一般操作,如从磁盘.其他系统.数据库等,CPU计算速度和数据读取速度已经严重失衡.假设印刷过程中一个线程将 ...