首页 > 代码库 > Leetcode#118 Pascal's Triangle

Leetcode#118 Pascal's Triangle

原题地址

 

基本模拟题

 

代码:

 1 vector<vector<int> > generate(int numRows) { 2         vector<vector<int> > res; 3          4         if (numRows <= 0) 5             return res; 6              7         res.push_back(vector<int>(1, 1)); 8         while (--numRows) { 9             vector<int> layer;10             layer.push_back(1);11             for (int i = 0; i + 1 < res.back().size(); i++)12                 layer.push_back(res.back()[i] + res.back()[i + 1]);13             layer.push_back(1);14             res.push_back(layer);15         }16         17         return res;18 }

 

Leetcode#118 Pascal's Triangle