Share my 3ms C solution


  • -3
    R
    vector<vector<int> > generate(int numRows) {
    	vector<vector<int> > ans;
    	vector<int> row;
    	for(int i=0;i<numRows;++i){
    		row.clear();
    		row.push_back(1);
    		int j;
    		for(j=1;j<=i/2;++j)
    			row.push_back(ans[i-1][j]+ans[i-1][j-1]);
    		for(;j<i+1;++j)
    			row.push_back(row[i-j]);
    		ans.push_back(row);
    	}
    	return ans;
    }

Log in to reply
 

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