A 0 ms C++ solution


  • 0
    vector<vector<int>> generate(int n) 
    {
    	vector<vector<int>> null;
    	if (!n)
    		return null;
    	vector<vector<int>> res = { { 1 } };
    	if (1 == n)
    		return res;
    	vector<int> a = { 0, 1, 0 };
    	int i, j;
    	for (i = 2; i <= n; ++i)
    	{
    		vector<int> t;
    		for (j = 0; j < a.size() - 1; ++j)
    			t.push_back(a[j] + a[j + 1]);
    		res.push_back(t);
    		a = t;
    		a.insert(a.begin(), 0);
    		a.push_back(0);
    	}
    	return res;
    }

Log in to reply
 

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