标签:
Given an index k, return the kth row of the Pascal‘s triangle.
For example, given k = 3,
Return [1,3,3,1]
.
分析 二项式展开式的系数 不加(long long)提交会出错。
1 class Solution { 2 public: 3 vector<int> getRow(int rowIndex) { 4 vector<int> vals; 5 6 vals.resize(rowIndex+1); 7 vals[0] = 1; 8 9 for(int i = 1; i <= rowIndex;i++) 10 vals[i] = (long long)vals[i-1]*(rowIndex-i+1)/i; 11 12 return vals; 13 } 14 };
标签:
原文地址:http://www.cnblogs.com/sankexin/p/5863088.html