Leetcode_119--pascal ' s Triangle II (simple, simple recursion)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.