摘要: Q:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note: extra space: O(K)A: 开辟k+1大的空间用于存储结果。做K+1次迭代。第i次迭代,将result[i]置成1,同时对于j:[1,i-1],result[j] = result[j] + old result[j-1]; vector<int> getRow(int rowIndex) { // Start typing your C/C++ sol 阅读全文
posted @ 2013-06-13 21:57 summer_zhou 阅读(142) 评论(0) 推荐(0)
摘要: Q: 杨辉三角A:1. 左右两端的数都为12. 每个数字等于上一行的左右两个数字之和。3. 每行数字左右对称,由1开始逐渐变大。4. 第n行的数字有n项。 vector<vector<int> > generate(int numRows) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<vector<int> > result; if(numRows<=0) return ... 阅读全文
posted @ 2013-06-13 20:16 summer_zhou 阅读(136) 评论(0) 推荐(0)
摘要: Q:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.A:Findiandjthat maximizes Aj- Ai, wherei<j. int maxPro 阅读全文
posted @ 2013-06-13 19:47 summer_zhou 阅读(113) 评论(0) 推荐(0)