leetcode先刷_Pascal's Triangle II
三角相对简答题。第一个问题是太简单。我不沾了,我一定会写。其实没什么的第二个问题,与这个问题计算路径有点像一个三角形,假定输入是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's Triangle II的更多相关文章
- 【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 ...
- 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, ...
- 【一天一道LeetCode】#119. Pascal's Triangle II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 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 ...
- [LeetCode]Pascal's Triangle II
题目:给定一个行索引index,返回帕斯卡三角形第index层的三角形 算法:生成index层帕斯卡三角形,并返回第index层三角形 public class Solution { public L ...
- 【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 ...
- 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】119. Pascal's Triangle II
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...
- LeetCode算法题-Pascal's Triangle II(Java实现)
这是悦乐书的第171次更新,第173篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第30题(顺位题号是119).给定非负索引k,其中k≤33,返回Pascal三角形的第k ...
随机推荐
- Android 输入框弹出样式
在androidMainfest.xml文件里 在Activity中设置 [A]stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置 [B]stateU ...
- "Swift"编程语言
来自英文文档.百度翻译以及自己没过4级的渣渣英语功底,为了自己以后看起来方便 About Swift 关于"海燕" IMPORTANT 重要 This is a prelimina ...
- 【codeforces 760B】Frodo and pillows
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Java中sleep()与wait()区别
学习时正好碰到这两个方法,就查阅相关资料,并通过程序实现,进行区别一下: 1.每个对象都有一个锁来控制同步访问,Synchronized关键字可以和对象的锁交互,来实现同步方法或同步块.sleep() ...
- 排序算法 基于Javascript
写在前面 个人感觉:javascript对类似排序查找这样的功能已经有了很好的封装,以致于当我们想对数组排序的时候只需要调用arr.sort()方法,而查找数组元素也只需要调用indexOf()方法或 ...
- iOS9.0 生成证书流程一(非推送)
1.首先进入网址 http://developer.apple.com 2.第二登入,点击
- Winform 中tabcontrol 美化
需要对tabcontrol按照美工出的图进行美化 对tabpage页进行标题设置,首先对整个tabcontrol的DrawMode设置为OwnerDrawFixed,由于需要对标题宽度有要求,设置si ...
- 【t012】整理书架
Time Limit: 1 second Memory Limit: 32 MB [问题描述] 小明是一个非常喜欢读书的孩子,他有一个特别的书架,书架上摆放着他买的新书.当他决定要阅读某本图书时,他就 ...
- cordova之File Transfer (Permission denied) 权限导致下载失败 - 简书
原文:cordova之File Transfer (Permission denied) 权限导致下载失败 - 简书 在文件上传时,由于权限问题,会报错(Permission denied),安卓6. ...
- webcollector + selenium 爬取空间相册图片
package cn.hb.util; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWr ...