leetcode_119-Pascal's Triangle II(간단한 문제, 간단한 귀속)

1290 단어 LeetCode

Pascal's Triangle II

 
Total Accepted: 39663 Total Submissions: 134813 My Submissions
Question
 Solution 
 
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?
 
Hide Tags
 
Array
Have you met this question in a real intervie
이 문제는 간단한 문제이니 차례대로 하면 된다
#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()

{



}


  

좋은 웹페이지 즐겨찾기