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