博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[leetcode-119-Pascal's Triangle II]
阅读量:6984 次
发布时间:2019-06-27

本文共 801 字,大约阅读时间需要 2 分钟。

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?

vector
getRow(int rowIndex) { vector
result; vector
temp; if (rowIndex < 0)return result; temp.push_back(1); if (rowIndex == 0)return temp; for (int i = 0; i <= rowIndex;i++) { result.clear(); result.push_back(1); for (int j = 1; j < i; j++) { result.push_back(temp[j - 1] + temp[j]); } result.push_back(1); temp = result; } return result; }

 

转载于:https://www.cnblogs.com/hellowooorld/p/6669771.html

你可能感兴趣的文章
算出两个经纬度的距离(米)
查看>>
我的友情链接
查看>>
树莓派2代B model 上手初体验,不用显示器,Python GPIO 点亮一颗LED
查看>>
Kotlin 4 构造,对象,修饰符,关键字,委托
查看>>
ios改变字体
查看>>
Android的ClassLoader知多少
查看>>
&quot;愿有人陪你颠沛流离|Be With You&quot;
查看>>
[阅读笔记] Java 7 新特性
查看>>
201621123028《Java程序设计》第5周学习总结
查看>>
软件体系结构C2风格
查看>>
flex自定义的分区域状态显示控件——原创
查看>>
best introduction to camera calibration
查看>>
1115 Counting Nodes in a BST
查看>>
ComboBox的真实值和显示值
查看>>
SQLI_LAB——Less7~15
查看>>
关于kafka生产者相关监控指标的理解(未解决)
查看>>
Ubuntu中搭建Hadoop2.5.2完全分布式系统(一)
查看>>
C++ new delete(二)
查看>>
css写出三角形(兼容IE)
查看>>
Ibatis.net 属性字段中使用 IN 查询条件
查看>>