We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents b0ffb4d + 3e43c3a commit 058a583Copy full SHA for 058a583
src/pascalTriangle/pascalTriangle.II.cpp
@@ -21,21 +21,14 @@
21
using namespace std;
22
23
vector<int> getRow(int rowIndex) {
24
- vector<int> v;
25
- for(int i=0; i<rowIndex; i++){
26
- if(i==0){
27
- v.push_back(1);
28
- }else{
29
- v.push_back(0);
30
- }
31
+ vector<int> v(rowIndex+1, 0);
+ v[0]=1;
32
33
for (int i=0; i<rowIndex; i++){
34
for(int j=i+1; j>0; j--){
35
v[j] += v[j-1];
36
}
37
38
39
return v;
40
41
@@ -51,6 +44,9 @@ void printVector( vector<int> pt)
51
44
52
45
int main(int argc, char** argv)
53
46
{
54
- int n = atoi(argv[1]);
47
+ int n = 3;
48
+ if (argc>1) {
49
+ n = atoi(argv[1]);
50
+ }
55
printVector(getRow(n));
56
0 commit comments