My simple c++ solution


  • 0
    K
    class Solution {
    public:
    vector<vector<int>> generate(int rows) {
        vector<vector<int>>res;
        if(rows>0)res.push_back({1});
        for(int i=1;i<rows;i++)
        {
            vector<int>array=res.back(), temp;
            temp.push_back(array.front());
            int j=1;
            while(j<array.size())
            {
                temp.push_back(array[j-1]+array[j]);
                j++;
            }
            temp.push_back(array.back());
            res.push_back(temp);
        }
        return res;
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.