leetcode_119——Pascal's Triangle II (简单题,简单的递归)
2015-05-04 18:10
429 查看
Pascal's Triangle II
Total Accepted: 39663 Total Submissions: 134813My SubmissionsQuestion 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() { }
相关文章推荐
- [LeetCode] 119. Pascal's Triangle II 杨辉三角 II
- Leetcode 119 Pascal's Triangle II 数论递推
- LeetCode(119) Pascal's Triangle II
- [LeetCode 119] - 杨辉三角形II(Pascal's Triangle II)
- 每天一道LeetCode--119.Pascal's Triangle II(杨辉三角)
- LeetCode#119 Pascal's Triangle II
- LeetCode 119. Pascal's Triangle II
- Pascal's Triangle II leetcode
- 【leetcode】【119】Pascal's Triangle II
- 119. Pascal's Triangle II
- LeetCode 119. Pascal's Triangle II
- leetcode119. Pascal's Triangle II
- leetcode_question_119 Pascal's Triangle II
- [Leetcode]119. Pascal's Triangle II
- LeetCode:Pascal's Triangle I II
- [LeetCode By Python]119. Pascal's Triangle II
- LeetCode119 Pascal's Triangle II
- LeetCode WIith JS || 119. Pascal's Triangle II
- Leetcode 119. Pascal's Triangle II
- 【Leetcode】119. Pascal's Triangle II