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?

  

class Solution {
public:
vector<int> getRow(int rowIndex) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int> result(rowIndex+);
result[] = ; int temp1 = , temp2 = ;
for(int i = ; i<= rowIndex ; i++)
for(int j = ; j< i+; j++){
temp2 = result[j];
if(j == || j == i)
result[j] = ;
else
result[j] += temp1 ;
temp1 = temp2;
} return result;
}
};

最新文章

  1. PHP单例模式
  2. 一定要在主线程更新UI
  3. padding(内边距)、margin(外边距)、border(边框)
  4. Matlab中函数定义方法
  5. POJ 3216 最小路径覆盖+floyd
  6. gulp和webpack初探
  7. SHELL:Find Memory Usage In Linux (统计每个程序内存使用情况)
  8. javascript定义变量和优先级的问题
  9. Android系统默认Home应用程序(Launcher)的启动过程源代码分析
  10. Java中如何创建线程
  11. 自学java能不能找到找到一份java工作。
  12. Python 学习笔记9 循环语句 For in
  13. ApiDoc官方文档
  14. Shell中判断文件,目录是否存在
  15. 汇编语言--微机CPU的指令系统(五)(循环指令)
  16. C/C++的内存泄漏检测工具Valgrind memcheck的使用经历
  17. 【python005-数据类型】
  18. 【opencv基础】OpenCV installation stuck at [ 98%] Built target opencv_perf_stitching with no error
  19. Revit API得到类别Category设置类别可见性
  20. OC - runtime - 1

热门文章

  1. LeetCode_3 sum
  2. 自制单片机之十二……AT89C2051烧写器的制做与调试
  3. AzCopy – 上传/下载 Windows Azure Blob 文件
  4. sqlite3 C API编程
  5. Javascript:一款简易的图片切换插件
  6. Direct2D 简介
  7. [CSAPP笔记][第十二章并发编程]
  8. CodeSmith使用总结--创建一个基础模板
  9. js数组 函数
  10. C#的位运算符