Pascal ' s Triangle IITotal accepted:39663 Total submissions:134813my submissions QuestionSolution
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 optimize your algorithm to use only O(k) extra space?
Hide TagsArrayHas you met this question in a real intervieThis problem is a simple question, you can use recursion.
#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 (simple, simple recursion)