-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path118.pascals-triangle.cpp
More file actions
39 lines (33 loc) · 934 Bytes
/
118.pascals-triangle.cpp
File metadata and controls
39 lines (33 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "testharness.h"
#include <map>
#include <string>
#include <string.h>
#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
vector<vector<int> > generate(int numRows) {
vector<vector<int>> result;
if (numRows < 1) return result;
result.resize(numRows, vector<int>({1}));
for (int i = 1; i < numRows; i++) {
result[i].resize(i+1);
for (int j = 1; j < i; j++) {
result[i][j] = result[i-1][j-1] + result[i-1][j];
}
result[i][i] = 1;
}
return result;
}
};
TEST(Solution, test) {
ASSERT_EQ(2, 1+1);
auto result = generate(15);
for (auto iter1 = result.begin(); iter1 != result.end(); ++iter1) {
for (auto iter2 = (*iter1).begin(); iter2 != (*iter1).end(); ++iter2) {
std::cout << *iter2 << " ";
}
std::cout << endl;
}
}