判斷 當前列的列號 為第一列或者為最后一列的時候,該值為1
中間的其他列,為上一行的當前列號的值 + 列號減一的值
class Solution {
public:vector<int> getRow(int rowIndex) {vector<int> ans;if(rowIndex == 0) return vector<int>(1,1);if(rowIndex == 1) return vector<int>(2,1);vector<int> tmp(2,1);for(int i = 2 ;i <= rowIndex ; i++){ans.clear();for(int j = 0 ;j <= i ; j++){if(j == 0 || j == i) ans.emplace_back(1);else{ans.emplace_back(tmp[j] + tmp[j-1]);}}tmp = ans;}return ans;}
};
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态