Pascal's Triangle II

class Solution {
public:
    vector<int> getRow(int rowIndex) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        vector<int> result;
        if(rowIndex<0)
        return result;
        vector<int> temp;
        temp.push_back(1);
        result = temp;
        for(int i = 1;i<=rowIndex;i++)
        {
            temp.clear();
            temp.push_back(1);
            for(int j = 1;j<i;j++)
            {
                temp.push_back(result[j-1]+result[j]);
            }
            temp.push_back(1);
            result = temp;
        }
        return result;
    }
};

 

posted on 2013-09-10 15:34  邪灵天使  阅读(105)  评论(0编辑  收藏  举报