LeetCode 119. Pascal’s Triangle II
2016-07-22 02:01
501 查看
119. Pascal’s Triangle II
My Submissions QuestionEditorial Solution
Total Accepted: 72147 Total Submissions: 224801 Difficulty: Easy
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?
My Submissions QuestionEditorial Solution
Total Accepted: 72147 Total Submissions: 224801 Difficulty: Easy
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?
class Solution { public: vector<int> getRow(int rowIndex) { vector<int> v(rowIndex + 1); v[0] = 1; for(int i = 1; i <= rowIndex; i++) { v[i] = (long long int)v[i - 1] *(long long int)(rowIndex - i + 1) / i; } return v; } };
相关文章推荐
- LeetCode 189. Rotate Array
- 类的加载顺序
- Codeforces Beta Round #72 (Div. 2 Only)D. Doctor
- 固本培元之四:这个需要回头体会
- WebUploader的java后端上传代码(支持分片上传)(未测试)
- LeetCode 62. Unique Paths
- Codeforces Beta Round #72 (Div. 2 Only)D. Doctor
- HDU5737 : Differencia
- ftp 实现文件的上传下载以及列出文件列表Java代码(未测试)
- LeetCode 101. Symmetric Tree
- LeetCode 9. Palindrome Number
- LeetCode 107. Binary Tree Level Order Traversal II
- LeetCode 102. Binary Tree Level Order Traversal
- PHP 连接 MSSQL
- 套路重写Java的equals函数
- LeetCode 35. Search Insert Position
- 400异常
- java中常用的时间处理类TimeUtil
- LeetCode 36. Valid Sudoku
- LeetCode 112. Path Sum