-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path119.cpp
More file actions
51 lines (38 loc) · 920 Bytes
/
119.cpp
File metadata and controls
51 lines (38 loc) · 920 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
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<vector>
std::vector<int> getRow(int rowIndex) {
if(rowIndex == 0) {
return {1};
}
if(rowIndex == 1) {
return {1, 1};
}
std::vector<int> vec = {};
std::vector<int> temp = {};
vec.push_back(1);
vec.push_back(1);
int update_indx = 0;
int update_indx1 = 1;
for(int i = 0; i < rowIndex - 1; ++i) {
temp.push_back(1);
for(int j = 0; j <= i; ++j) {
temp.push_back(vec[update_indx] + vec[update_indx1]);
++update_indx;
++update_indx1;
}
temp.push_back(1);
update_indx = 0;
update_indx1 = 1;
vec = temp;
temp.erase(temp.begin(), temp.end());
}
return vec;
}
int main() {
int rowIndex = 4;
std::vector<int> vec = getRow(rowIndex);
for(int i : vec) {
std::cout << i << " ";
}
std::cin.get();
}