[Array]Pascal's Triangle II
生活随笔
收集整理的這篇文章主要介紹了
[Array]Pascal's Triangle II
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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> res(rowIndex+1);for(int i=0;i<rowIndex+1;i++){res[0]=1;for(int j=i;j>=1;j--)res[j]=res[j-1]+res[j];}return res;} };轉載于:https://www.cnblogs.com/GoFly/p/5751060.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的[Array]Pascal's Triangle II的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 事件大全
- 下一篇: java servlet拾遗(1)-Se