标签:class nbsp vector row ext pre get res asc
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?
只用O(k)的额外空间,求第K行帕斯卡三角形的数
C++(0ms):
1 class Solution { 2 public: 3 vector<int> getRow(int rowIndex) { 4 vector<int> res(rowIndex+1,0) ; 5 res[0] = 1 ; 6 for(int i = 1 ; i < rowIndex+1 ; i++){ 7 for(int j = i ; j >=1 ; j--){ 8 res[j] += res[j-1] ; 9 } 10 } 11 return res ; 12 } 13 };
标签:class nbsp vector row ext pre get res asc
原文地址:http://www.cnblogs.com/-Buff-/p/7581194.html