标签:
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?
Array
#include<iostream> #include<vector> using namespace std; vector<int> getRow(int rowIndex) { vector<int> vec; vector<int> temp; if(rowIndex==0) { vec.push_back(1); return vec; } if(rowIndex==1) { vec.push_back(1),vec.push_back(1); return vec; } temp=getRow(rowIndex-1); vec.push_back(1); int len=temp.size(); for(int i=0;i<len-1;i++) vec.push_back(temp[i]+temp[i+1]); vec.push_back(1); return vec; } int main() { }
leetcode_119——Pascal's Triangle II (简单题,简单的递归)
标签:
原文地址:http://www.cnblogs.com/yanliang12138/p/4476892.html