leetcode 111 —— Pascal's Triangle

来源:互联网 发布:pl sql developer查询 编辑:程序博客网 时间:2024/05/21 12:25

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 numRows) {vector<int> path;for (int i = 0; i <= numRows; i++){int tmp=1;for (int j = 1; j < i; j++){path[j]=path[j]+tmp;tmp = path[j] - tmp;}path.push_back(1);}return path;}};




0 0
原创粉丝点击